{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>login_time</th>\n",
       "      <th>login_place</th>\n",
       "      <th>country</th>\n",
       "      <th>province</th>\n",
       "      <th>city</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-06 09:32:47</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-07 09:28:28</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-07 09:57:44</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-07 10:55:07</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-07 12:28:42</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>387139</th>\n",
       "      <td>用户44247</td>\n",
       "      <td>2020-06-18 07:41:22</td>\n",
       "      <td>中国湖北武汉</td>\n",
       "      <td>中国</td>\n",
       "      <td>湖北</td>\n",
       "      <td>武汉</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>387140</th>\n",
       "      <td>用户44247</td>\n",
       "      <td>2020-06-18 08:13:28</td>\n",
       "      <td>中国湖北</td>\n",
       "      <td>中国</td>\n",
       "      <td>湖北</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>387141</th>\n",
       "      <td>用户44248</td>\n",
       "      <td>2020-06-18 09:09:07</td>\n",
       "      <td>中国天津</td>\n",
       "      <td>中国</td>\n",
       "      <td>天津</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>387142</th>\n",
       "      <td>用户44249</td>\n",
       "      <td>2020-06-18 09:43:15</td>\n",
       "      <td>中国北京</td>\n",
       "      <td>中国</td>\n",
       "      <td>北京</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>387143</th>\n",
       "      <td>用户44250</td>\n",
       "      <td>2020-06-18 09:48:00</td>\n",
       "      <td>中国江西南昌</td>\n",
       "      <td>中国</td>\n",
       "      <td>江西</td>\n",
       "      <td>南昌</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>387144 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        user_id           login_time login_place country province city\n",
       "0           用户3  2018-09-06 09:32:47      中国广东广州      中国       广东   广州\n",
       "1           用户3  2018-09-07 09:28:28      中国广东广州      中国       广东   广州\n",
       "2           用户3  2018-09-07 09:57:44      中国广东广州      中国       广东   广州\n",
       "3           用户3  2018-09-07 10:55:07      中国广东广州      中国       广东   广州\n",
       "4           用户3  2018-09-07 12:28:42      中国广东广州      中国       广东   广州\n",
       "...         ...                  ...         ...     ...      ...  ...\n",
       "387139  用户44247  2020-06-18 07:41:22      中国湖北武汉      中国       湖北   武汉\n",
       "387140  用户44247  2020-06-18 08:13:28        中国湖北      中国       湖北  NaN\n",
       "387141  用户44248  2020-06-18 09:09:07        中国天津      中国       天津  NaN\n",
       "387142  用户44249  2020-06-18 09:43:15        中国北京      中国       北京  NaN\n",
       "387143  用户44250  2020-06-18 09:48:00      中国江西南昌      中国       江西   南昌\n",
       "\n",
       "[387144 rows x 6 columns]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "login = pd.read_csv(\"data/login_processed.csv\",encoding='gbk')\n",
    "login"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>register_time</th>\n",
       "      <th>recently_logged</th>\n",
       "      <th>number_of_classes_join</th>\n",
       "      <th>number_of_classes_out</th>\n",
       "      <th>learn_time</th>\n",
       "      <th>school</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>用户44251</td>\n",
       "      <td>2020-06-18 09:49:00</td>\n",
       "      <td>2020-06-18 09:49:00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>41.25</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>用户44250</td>\n",
       "      <td>2020-06-18 09:47:00</td>\n",
       "      <td>2020-06-18 09:48:00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>用户44249</td>\n",
       "      <td>2020-06-18 09:43:00</td>\n",
       "      <td>2020-06-18 09:43:00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>16.22</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>用户44248</td>\n",
       "      <td>2020-06-18 09:09:00</td>\n",
       "      <td>2020-06-18 09:09:00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>用户44247</td>\n",
       "      <td>2020-06-18 07:41:00</td>\n",
       "      <td>2020-06-18 08:15:00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.80</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   user_id        register_time      recently_logged  number_of_classes_join  \\\n",
       "0  用户44251  2020-06-18 09:49:00  2020-06-18 09:49:00                       0   \n",
       "1  用户44250  2020-06-18 09:47:00  2020-06-18 09:48:00                       0   \n",
       "2  用户44249  2020-06-18 09:43:00  2020-06-18 09:43:00                       0   \n",
       "3  用户44248  2020-06-18 09:09:00  2020-06-18 09:09:00                       0   \n",
       "4  用户44247  2020-06-18 07:41:00  2020-06-18 08:15:00                       0   \n",
       "\n",
       "   number_of_classes_out  learn_time school  \n",
       "0                      0       41.25    NaN  \n",
       "1                      0        0.00    NaN  \n",
       "2                      0       16.22    NaN  \n",
       "3                      0        0.00    NaN  \n",
       "4                      0        1.80    NaN  "
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user = pd.read_csv(\"data/users_processed.csv\",encoding='gbk')\n",
    "user.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1、总用户量、最大学习时长、总交易额"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "43715"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user_total = user.user_id.count()\n",
    "user_total"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "58530.88"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Maxlearn_time = user.learn_time.max()\n",
    "Maxlearn_time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>course_id</th>\n",
       "      <th>course_join_time</th>\n",
       "      <th>learn_process</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>用户3</td>\n",
       "      <td>课程106</td>\n",
       "      <td>2020-04-21 10:11:50</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>用户3</td>\n",
       "      <td>课程136</td>\n",
       "      <td>2020-03-05 11:44:36</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>用户3</td>\n",
       "      <td>课程205</td>\n",
       "      <td>2018-09-10 18:17:01</td>\n",
       "      <td>63</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>用户4</td>\n",
       "      <td>课程26</td>\n",
       "      <td>2020-03-31 10:52:51</td>\n",
       "      <td>0</td>\n",
       "      <td>319.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>用户4</td>\n",
       "      <td>课程34</td>\n",
       "      <td>2020-03-31 10:52:49</td>\n",
       "      <td>0</td>\n",
       "      <td>299.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  user_id course_id     course_join_time  learn_process  price\n",
       "0     用户3     课程106  2020-04-21 10:11:50              0    0.0\n",
       "1     用户3     课程136  2020-03-05 11:44:36              1    0.0\n",
       "2     用户3     课程205  2018-09-10 18:17:01             63    0.0\n",
       "3     用户4      课程26  2020-03-31 10:52:51              0  319.0\n",
       "4     用户4      课程34  2020-03-31 10:52:49              0  299.0"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "study_information = pd.read_csv(\"data/study_information_processed.csv\",encoding='gbk')\n",
    "study_information.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "36586009"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "price_total = study_information.price.sum()\n",
    "price_total = price_total.astype(np.int64)\n",
    "price_total"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "number_total = pd.DataFrame(columns=['user_total','maxlearn_time','price_total'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_total</th>\n",
       "      <th>maxlearn_time</th>\n",
       "      <th>price_total</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>43715</td>\n",
       "      <td>58530.88</td>\n",
       "      <td>36586009</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   user_total  maxlearn_time  price_total\n",
       "0       43715       58530.88     36586009"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "number_total['user_total'] = [user_total]\n",
    "number_total['maxlearn_time'] = [Maxlearn_time]\n",
    "number_total['price_total'] = [price_total]\n",
    "number_total"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 保存至数据库"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "import MySQLdb\n",
    "import pandas as pd\n",
    "import sqlalchemy\n",
    "from sqlalchemy import create_engine"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "engine = create_engine('mysql+pymysql://root:root@localhost/course?charset=utf8')\n",
    "try:\n",
    "    number_total.to_sql('number_total',engine,index=False)\n",
    "except Exception as e:\n",
    "    print(e)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2、海外用户登录次数分析\n",
    "#### 折线图，海外用户分布：采用占比统计，该国用户占比=该国用户数量/海外各国用户总数量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "中国    386914\n",
       "英国       151\n",
       "越南        27\n",
       "德国        24\n",
       "荷兰         8\n",
       "波兰         7\n",
       "捷克         4\n",
       "南非         3\n",
       "泰国         2\n",
       "挪威         1\n",
       "瑞士         1\n",
       "瑞典         1\n",
       "希腊         1\n",
       "Name: country, dtype: int64"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "login.country.value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>county</th>\n",
       "      <th>login_counts</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>英国</td>\n",
       "      <td>151</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>越南</td>\n",
       "      <td>27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>德国</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>荷兰</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>波兰</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>捷克</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>南非</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>泰国</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>瑞士</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>挪威</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>瑞典</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>希腊</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   county  login_counts\n",
       "0      英国           151\n",
       "1      越南            27\n",
       "2      德国            24\n",
       "3      荷兰             8\n",
       "4      波兰             7\n",
       "5      捷克             4\n",
       "6      南非             3\n",
       "7      泰国             2\n",
       "8      瑞士             1\n",
       "9      挪威             1\n",
       "10     瑞典             1\n",
       "11     希腊             1"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "foreign_country = pd.DataFrame([[\"英国\",151],[\"越南\",27],[\"德国\",24],[\"荷兰\",8],\n",
    "                                [\"波兰\",7],[\"捷克\",4],[\"南非\",3],[\"泰国\",2],[\"瑞士\",1],\n",
    "                               [\"挪威\",1],[\"瑞典\",1],[\"希腊\",1]],columns=[\"county\",\"login_counts\"])\n",
    "foreign_country"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "230"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "login_total = foreign_country.login_counts.sum()\n",
    "login_total"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>county</th>\n",
       "      <th>login_counts</th>\n",
       "      <th>rate</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>英国</td>\n",
       "      <td>151</td>\n",
       "      <td>0.656522</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>越南</td>\n",
       "      <td>27</td>\n",
       "      <td>0.117391</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>德国</td>\n",
       "      <td>24</td>\n",
       "      <td>0.104348</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>荷兰</td>\n",
       "      <td>8</td>\n",
       "      <td>0.034783</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>波兰</td>\n",
       "      <td>7</td>\n",
       "      <td>0.030435</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>捷克</td>\n",
       "      <td>4</td>\n",
       "      <td>0.017391</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>南非</td>\n",
       "      <td>3</td>\n",
       "      <td>0.013043</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>泰国</td>\n",
       "      <td>2</td>\n",
       "      <td>0.008696</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>瑞士</td>\n",
       "      <td>1</td>\n",
       "      <td>0.004348</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>挪威</td>\n",
       "      <td>1</td>\n",
       "      <td>0.004348</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>瑞典</td>\n",
       "      <td>1</td>\n",
       "      <td>0.004348</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>希腊</td>\n",
       "      <td>1</td>\n",
       "      <td>0.004348</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   county  login_counts      rate\n",
       "0      英国           151  0.656522\n",
       "1      越南            27  0.117391\n",
       "2      德国            24  0.104348\n",
       "3      荷兰             8  0.034783\n",
       "4      波兰             7  0.030435\n",
       "5      捷克             4  0.017391\n",
       "6      南非             3  0.013043\n",
       "7      泰国             2  0.008696\n",
       "8      瑞士             1  0.004348\n",
       "9      挪威             1  0.004348\n",
       "10     瑞典             1  0.004348\n",
       "11     希腊             1  0.004348"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "foreign_country[\"rate\"] = foreign_country.login_counts/login_total\n",
    "foreign_country"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>county</th>\n",
       "      <th>login_counts</th>\n",
       "      <th>rate</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>英国</td>\n",
       "      <td>151</td>\n",
       "      <td>0.6565</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>越南</td>\n",
       "      <td>27</td>\n",
       "      <td>0.1174</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>德国</td>\n",
       "      <td>24</td>\n",
       "      <td>0.1043</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>荷兰</td>\n",
       "      <td>8</td>\n",
       "      <td>0.0348</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>波兰</td>\n",
       "      <td>7</td>\n",
       "      <td>0.0304</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>捷克</td>\n",
       "      <td>4</td>\n",
       "      <td>0.0174</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>南非</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0130</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>泰国</td>\n",
       "      <td>2</td>\n",
       "      <td>0.0087</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>瑞士</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0043</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>挪威</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0043</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>瑞典</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0043</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>希腊</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0043</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   county  login_counts    rate\n",
       "0      英国           151  0.6565\n",
       "1      越南            27  0.1174\n",
       "2      德国            24  0.1043\n",
       "3      荷兰             8  0.0348\n",
       "4      波兰             7  0.0304\n",
       "5      捷克             4  0.0174\n",
       "6      南非             3  0.0130\n",
       "7      泰国             2  0.0087\n",
       "8      瑞士             1  0.0043\n",
       "9      挪威             1  0.0043\n",
       "10     瑞典             1  0.0043\n",
       "11     希腊             1  0.0043"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "foreign_country[\"rate\"] = foreign_country[\"rate\"].round(4)\n",
    "foreign_country"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "try:\n",
    "    foreign_country.to_sql('foreign_country',engine,index=False)\n",
    "except Exception as e:\n",
    "    print(e)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "foreign_country.to_csv('data0/foreign_country.csv',encoding='gbk',index=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3、全国省份登录人数分布\n",
    "#### 热力图，统计各省份用户登录次数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "广东     120887\n",
       "湖北      33149\n",
       "贵州      18786\n",
       "河南      18550\n",
       "山东      14874\n",
       "河北      14708\n",
       "广西      14052\n",
       "浙江      13366\n",
       "重庆      13163\n",
       "湖南      13103\n",
       "四川      13099\n",
       "陕西      12088\n",
       "江苏      11237\n",
       "安徽      10332\n",
       "山西       8875\n",
       "福建       6558\n",
       "江西       5796\n",
       "上海       5365\n",
       "北京       4946\n",
       "甘肃       4138\n",
       "黑龙江      3775\n",
       "云南       3750\n",
       "辽宁       2917\n",
       "吉林       2285\n",
       "海南       2062\n",
       "内蒙古      1870\n",
       "天津       1805\n",
       "宁夏       1481\n",
       "新疆       1201\n",
       "青海        455\n",
       "香港        341\n",
       "澳门        171\n",
       "台湾        126\n",
       "西藏        102\n",
       "Name: province, dtype: int64"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "login.province.value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>province</th>\n",
       "      <th>login_counts</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>广东</td>\n",
       "      <td>120887</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>湖北</td>\n",
       "      <td>33149</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>贵州</td>\n",
       "      <td>18786</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>河南</td>\n",
       "      <td>18550</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>山东</td>\n",
       "      <td>14874</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>河北</td>\n",
       "      <td>14708</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>广西</td>\n",
       "      <td>14052</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>浙江</td>\n",
       "      <td>13366</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>重庆</td>\n",
       "      <td>13163</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>湖南</td>\n",
       "      <td>13103</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>四川</td>\n",
       "      <td>13099</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>陕西</td>\n",
       "      <td>12088</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>江苏</td>\n",
       "      <td>11237</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>安徽</td>\n",
       "      <td>10332</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>山西</td>\n",
       "      <td>8875</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>福建</td>\n",
       "      <td>6558</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>江西</td>\n",
       "      <td>5796</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>上海</td>\n",
       "      <td>5365</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>北京</td>\n",
       "      <td>4946</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>甘肃</td>\n",
       "      <td>4138</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>黑龙江</td>\n",
       "      <td>3775</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>云南</td>\n",
       "      <td>3750</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>辽宁</td>\n",
       "      <td>2917</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>吉林</td>\n",
       "      <td>2285</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>海南</td>\n",
       "      <td>2062</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>内蒙古</td>\n",
       "      <td>1870</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>天津</td>\n",
       "      <td>1805</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>宁夏</td>\n",
       "      <td>1481</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>新疆</td>\n",
       "      <td>1201</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>青海</td>\n",
       "      <td>455</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>香港</td>\n",
       "      <td>341</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>澳门</td>\n",
       "      <td>171</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>台湾</td>\n",
       "      <td>126</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>西藏</td>\n",
       "      <td>102</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   province  login_counts\n",
       "0        广东        120887\n",
       "1        湖北         33149\n",
       "2        贵州         18786\n",
       "3        河南         18550\n",
       "4        山东         14874\n",
       "5        河北         14708\n",
       "6        广西         14052\n",
       "7        浙江         13366\n",
       "8        重庆         13163\n",
       "9        湖南         13103\n",
       "10       四川         13099\n",
       "11       陕西         12088\n",
       "12       江苏         11237\n",
       "13       安徽         10332\n",
       "14       山西          8875\n",
       "15       福建          6558\n",
       "16       江西          5796\n",
       "17       上海          5365\n",
       "18       北京          4946\n",
       "19       甘肃          4138\n",
       "20      黑龙江          3775\n",
       "21       云南          3750\n",
       "22       辽宁          2917\n",
       "23       吉林          2285\n",
       "24       海南          2062\n",
       "25      内蒙古          1870\n",
       "26       天津          1805\n",
       "27       宁夏          1481\n",
       "28       新疆          1201\n",
       "29       青海           455\n",
       "30       香港           341\n",
       "31       澳门           171\n",
       "32       台湾           126\n",
       "33       西藏           102"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "province_login = pd.DataFrame(columns=[\"province\",\"login_counts\"])\n",
    "province_login['province'] = login.province.value_counts().index\n",
    "province_login['login_counts'] = login.province.value_counts().values\n",
    "province_login"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>province</th>\n",
       "      <th>login_counts</th>\n",
       "      <th>rank</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>广东</td>\n",
       "      <td>120887</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>湖北</td>\n",
       "      <td>33149</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>贵州</td>\n",
       "      <td>18786</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>河南</td>\n",
       "      <td>18550</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>山东</td>\n",
       "      <td>14874</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>河北</td>\n",
       "      <td>14708</td>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>广西</td>\n",
       "      <td>14052</td>\n",
       "      <td>7.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>浙江</td>\n",
       "      <td>13366</td>\n",
       "      <td>8.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>重庆</td>\n",
       "      <td>13163</td>\n",
       "      <td>9.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>湖南</td>\n",
       "      <td>13103</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>四川</td>\n",
       "      <td>13099</td>\n",
       "      <td>11.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>陕西</td>\n",
       "      <td>12088</td>\n",
       "      <td>12.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>江苏</td>\n",
       "      <td>11237</td>\n",
       "      <td>13.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>安徽</td>\n",
       "      <td>10332</td>\n",
       "      <td>14.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>山西</td>\n",
       "      <td>8875</td>\n",
       "      <td>15.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>福建</td>\n",
       "      <td>6558</td>\n",
       "      <td>16.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>江西</td>\n",
       "      <td>5796</td>\n",
       "      <td>17.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>上海</td>\n",
       "      <td>5365</td>\n",
       "      <td>18.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>北京</td>\n",
       "      <td>4946</td>\n",
       "      <td>19.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>甘肃</td>\n",
       "      <td>4138</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>黑龙江</td>\n",
       "      <td>3775</td>\n",
       "      <td>21.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>云南</td>\n",
       "      <td>3750</td>\n",
       "      <td>22.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>辽宁</td>\n",
       "      <td>2917</td>\n",
       "      <td>23.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>吉林</td>\n",
       "      <td>2285</td>\n",
       "      <td>24.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>海南</td>\n",
       "      <td>2062</td>\n",
       "      <td>25.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>内蒙古</td>\n",
       "      <td>1870</td>\n",
       "      <td>26.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>天津</td>\n",
       "      <td>1805</td>\n",
       "      <td>27.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>宁夏</td>\n",
       "      <td>1481</td>\n",
       "      <td>28.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>新疆</td>\n",
       "      <td>1201</td>\n",
       "      <td>29.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>青海</td>\n",
       "      <td>455</td>\n",
       "      <td>30.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>香港</td>\n",
       "      <td>341</td>\n",
       "      <td>31.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>澳门</td>\n",
       "      <td>171</td>\n",
       "      <td>32.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>台湾</td>\n",
       "      <td>126</td>\n",
       "      <td>33.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>西藏</td>\n",
       "      <td>102</td>\n",
       "      <td>34.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   province  login_counts  rank\n",
       "0        广东        120887   1.0\n",
       "1        湖北         33149   2.0\n",
       "2        贵州         18786   3.0\n",
       "3        河南         18550   4.0\n",
       "4        山东         14874   5.0\n",
       "5        河北         14708   6.0\n",
       "6        广西         14052   7.0\n",
       "7        浙江         13366   8.0\n",
       "8        重庆         13163   9.0\n",
       "9        湖南         13103  10.0\n",
       "10       四川         13099  11.0\n",
       "11       陕西         12088  12.0\n",
       "12       江苏         11237  13.0\n",
       "13       安徽         10332  14.0\n",
       "14       山西          8875  15.0\n",
       "15       福建          6558  16.0\n",
       "16       江西          5796  17.0\n",
       "17       上海          5365  18.0\n",
       "18       北京          4946  19.0\n",
       "19       甘肃          4138  20.0\n",
       "20      黑龙江          3775  21.0\n",
       "21       云南          3750  22.0\n",
       "22       辽宁          2917  23.0\n",
       "23       吉林          2285  24.0\n",
       "24       海南          2062  25.0\n",
       "25      内蒙古          1870  26.0\n",
       "26       天津          1805  27.0\n",
       "27       宁夏          1481  28.0\n",
       "28       新疆          1201  29.0\n",
       "29       青海           455  30.0\n",
       "30       香港           341  31.0\n",
       "31       澳门           171  32.0\n",
       "32       台湾           126  33.0\n",
       "33       西藏           102  34.0"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "province_login['rank'] = province_login['login_counts'].rank(ascending=False,method='first')\n",
    "province_login"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "province        object\n",
       "login_counts     int64\n",
       "rank             int64\n",
       "dtype: object"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "province_login['rank']= province_login['rank'].values.astype(np.int64)\n",
    "province_login.dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>province</th>\n",
       "      <th>login_counts</th>\n",
       "      <th>rank</th>\n",
       "      <th>rate</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>广东</td>\n",
       "      <td>120887</td>\n",
       "      <td>1</td>\n",
       "      <td>0.318616</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>湖北</td>\n",
       "      <td>33149</td>\n",
       "      <td>2</td>\n",
       "      <td>0.087369</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>贵州</td>\n",
       "      <td>18786</td>\n",
       "      <td>3</td>\n",
       "      <td>0.049513</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>河南</td>\n",
       "      <td>18550</td>\n",
       "      <td>4</td>\n",
       "      <td>0.048891</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>山东</td>\n",
       "      <td>14874</td>\n",
       "      <td>5</td>\n",
       "      <td>0.039203</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>河北</td>\n",
       "      <td>14708</td>\n",
       "      <td>6</td>\n",
       "      <td>0.038765</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>广西</td>\n",
       "      <td>14052</td>\n",
       "      <td>7</td>\n",
       "      <td>0.037036</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>浙江</td>\n",
       "      <td>13366</td>\n",
       "      <td>8</td>\n",
       "      <td>0.035228</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>重庆</td>\n",
       "      <td>13163</td>\n",
       "      <td>9</td>\n",
       "      <td>0.034693</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>湖南</td>\n",
       "      <td>13103</td>\n",
       "      <td>10</td>\n",
       "      <td>0.034535</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>四川</td>\n",
       "      <td>13099</td>\n",
       "      <td>11</td>\n",
       "      <td>0.034524</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>陕西</td>\n",
       "      <td>12088</td>\n",
       "      <td>12</td>\n",
       "      <td>0.031860</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>江苏</td>\n",
       "      <td>11237</td>\n",
       "      <td>13</td>\n",
       "      <td>0.029617</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>安徽</td>\n",
       "      <td>10332</td>\n",
       "      <td>14</td>\n",
       "      <td>0.027232</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>山西</td>\n",
       "      <td>8875</td>\n",
       "      <td>15</td>\n",
       "      <td>0.023391</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>福建</td>\n",
       "      <td>6558</td>\n",
       "      <td>16</td>\n",
       "      <td>0.017285</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>江西</td>\n",
       "      <td>5796</td>\n",
       "      <td>17</td>\n",
       "      <td>0.015276</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>上海</td>\n",
       "      <td>5365</td>\n",
       "      <td>18</td>\n",
       "      <td>0.014140</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>北京</td>\n",
       "      <td>4946</td>\n",
       "      <td>19</td>\n",
       "      <td>0.013036</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>甘肃</td>\n",
       "      <td>4138</td>\n",
       "      <td>20</td>\n",
       "      <td>0.010906</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>黑龙江</td>\n",
       "      <td>3775</td>\n",
       "      <td>21</td>\n",
       "      <td>0.009950</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>云南</td>\n",
       "      <td>3750</td>\n",
       "      <td>22</td>\n",
       "      <td>0.009884</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>辽宁</td>\n",
       "      <td>2917</td>\n",
       "      <td>23</td>\n",
       "      <td>0.007688</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>吉林</td>\n",
       "      <td>2285</td>\n",
       "      <td>24</td>\n",
       "      <td>0.006022</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>海南</td>\n",
       "      <td>2062</td>\n",
       "      <td>25</td>\n",
       "      <td>0.005435</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>内蒙古</td>\n",
       "      <td>1870</td>\n",
       "      <td>26</td>\n",
       "      <td>0.004929</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>天津</td>\n",
       "      <td>1805</td>\n",
       "      <td>27</td>\n",
       "      <td>0.004757</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>宁夏</td>\n",
       "      <td>1481</td>\n",
       "      <td>28</td>\n",
       "      <td>0.003903</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>新疆</td>\n",
       "      <td>1201</td>\n",
       "      <td>29</td>\n",
       "      <td>0.003165</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>青海</td>\n",
       "      <td>455</td>\n",
       "      <td>30</td>\n",
       "      <td>0.001199</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>香港</td>\n",
       "      <td>341</td>\n",
       "      <td>31</td>\n",
       "      <td>0.000899</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>澳门</td>\n",
       "      <td>171</td>\n",
       "      <td>32</td>\n",
       "      <td>0.000451</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>台湾</td>\n",
       "      <td>126</td>\n",
       "      <td>33</td>\n",
       "      <td>0.000332</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>西藏</td>\n",
       "      <td>102</td>\n",
       "      <td>34</td>\n",
       "      <td>0.000269</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   province  login_counts  rank      rate\n",
       "0        广东        120887     1  0.318616\n",
       "1        湖北         33149     2  0.087369\n",
       "2        贵州         18786     3  0.049513\n",
       "3        河南         18550     4  0.048891\n",
       "4        山东         14874     5  0.039203\n",
       "5        河北         14708     6  0.038765\n",
       "6        广西         14052     7  0.037036\n",
       "7        浙江         13366     8  0.035228\n",
       "8        重庆         13163     9  0.034693\n",
       "9        湖南         13103    10  0.034535\n",
       "10       四川         13099    11  0.034524\n",
       "11       陕西         12088    12  0.031860\n",
       "12       江苏         11237    13  0.029617\n",
       "13       安徽         10332    14  0.027232\n",
       "14       山西          8875    15  0.023391\n",
       "15       福建          6558    16  0.017285\n",
       "16       江西          5796    17  0.015276\n",
       "17       上海          5365    18  0.014140\n",
       "18       北京          4946    19  0.013036\n",
       "19       甘肃          4138    20  0.010906\n",
       "20      黑龙江          3775    21  0.009950\n",
       "21       云南          3750    22  0.009884\n",
       "22       辽宁          2917    23  0.007688\n",
       "23       吉林          2285    24  0.006022\n",
       "24       海南          2062    25  0.005435\n",
       "25      内蒙古          1870    26  0.004929\n",
       "26       天津          1805    27  0.004757\n",
       "27       宁夏          1481    28  0.003903\n",
       "28       新疆          1201    29  0.003165\n",
       "29       青海           455    30  0.001199\n",
       "30       香港           341    31  0.000899\n",
       "31       澳门           171    32  0.000451\n",
       "32       台湾           126    33  0.000332\n",
       "33       西藏           102    34  0.000269"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "province_login[\"rate\"] = province_login.login_counts/province_login.login_counts.sum()\n",
    "province_login"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "try:\n",
    "    province_login.to_sql('province_login',engine,index=False)\n",
    "except Exception as e:\n",
    "    print(e)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "province_login.to_csv('data0/province_login.csv',encoding='gbk',index=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4、用户登录量前十省份分布\n",
    "#### 列表，采用占比，占比全国用户总登录量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>province</th>\n",
       "      <th>login_counts</th>\n",
       "      <th>rank</th>\n",
       "      <th>rate</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>广东</td>\n",
       "      <td>120887</td>\n",
       "      <td>1</td>\n",
       "      <td>0.318616</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>湖北</td>\n",
       "      <td>33149</td>\n",
       "      <td>2</td>\n",
       "      <td>0.087369</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>贵州</td>\n",
       "      <td>18786</td>\n",
       "      <td>3</td>\n",
       "      <td>0.049513</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>河南</td>\n",
       "      <td>18550</td>\n",
       "      <td>4</td>\n",
       "      <td>0.048891</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>山东</td>\n",
       "      <td>14874</td>\n",
       "      <td>5</td>\n",
       "      <td>0.039203</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>河北</td>\n",
       "      <td>14708</td>\n",
       "      <td>6</td>\n",
       "      <td>0.038765</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>广西</td>\n",
       "      <td>14052</td>\n",
       "      <td>7</td>\n",
       "      <td>0.037036</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>浙江</td>\n",
       "      <td>13366</td>\n",
       "      <td>8</td>\n",
       "      <td>0.035228</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>重庆</td>\n",
       "      <td>13163</td>\n",
       "      <td>9</td>\n",
       "      <td>0.034693</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>湖南</td>\n",
       "      <td>13103</td>\n",
       "      <td>10</td>\n",
       "      <td>0.034535</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  province  login_counts  rank      rate\n",
       "0       广东        120887     1  0.318616\n",
       "1       湖北         33149     2  0.087369\n",
       "2       贵州         18786     3  0.049513\n",
       "3       河南         18550     4  0.048891\n",
       "4       山东         14874     5  0.039203\n",
       "5       河北         14708     6  0.038765\n",
       "6       广西         14052     7  0.037036\n",
       "7       浙江         13366     8  0.035228\n",
       "8       重庆         13163     9  0.034693\n",
       "9       湖南         13103    10  0.034535"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "province_top10 = pd.DataFrame()\n",
    "province_top10 = province_login[province_login['rank'].isin(range(1,11))]\n",
    "province_top10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "<ipython-input-23-f5751f98e819>:1: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  province_top10['rate'] = province_top10['rate'].round(4)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>province</th>\n",
       "      <th>login_counts</th>\n",
       "      <th>rank</th>\n",
       "      <th>rate</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>广东</td>\n",
       "      <td>120887</td>\n",
       "      <td>1</td>\n",
       "      <td>0.3186</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>湖北</td>\n",
       "      <td>33149</td>\n",
       "      <td>2</td>\n",
       "      <td>0.0874</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>贵州</td>\n",
       "      <td>18786</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0495</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>河南</td>\n",
       "      <td>18550</td>\n",
       "      <td>4</td>\n",
       "      <td>0.0489</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>山东</td>\n",
       "      <td>14874</td>\n",
       "      <td>5</td>\n",
       "      <td>0.0392</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>河北</td>\n",
       "      <td>14708</td>\n",
       "      <td>6</td>\n",
       "      <td>0.0388</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>广西</td>\n",
       "      <td>14052</td>\n",
       "      <td>7</td>\n",
       "      <td>0.0370</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>浙江</td>\n",
       "      <td>13366</td>\n",
       "      <td>8</td>\n",
       "      <td>0.0352</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>重庆</td>\n",
       "      <td>13163</td>\n",
       "      <td>9</td>\n",
       "      <td>0.0347</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>湖南</td>\n",
       "      <td>13103</td>\n",
       "      <td>10</td>\n",
       "      <td>0.0345</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  province  login_counts  rank    rate\n",
       "0       广东        120887     1  0.3186\n",
       "1       湖北         33149     2  0.0874\n",
       "2       贵州         18786     3  0.0495\n",
       "3       河南         18550     4  0.0489\n",
       "4       山东         14874     5  0.0392\n",
       "5       河北         14708     6  0.0388\n",
       "6       广西         14052     7  0.0370\n",
       "7       浙江         13366     8  0.0352\n",
       "8       重庆         13163     9  0.0347\n",
       "9       湖南         13103    10  0.0345"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "province_top10['rate'] = province_top10['rate'].round(4)\n",
    "province_top10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "try:\n",
    "    province_top10.to_sql('province_top10',engine,index=False)\n",
    "except Exception as e:\n",
    "    print(e)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "province_top10.to_csv('data0/province_top10.csv',encoding='gbk',index=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 5、用户登录量前十城市分布\n",
    "#### 列表，采用占比，占比全国用户总登录量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>city</th>\n",
       "      <th>login_counts</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>广州</td>\n",
       "      <td>27626</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>汕头</td>\n",
       "      <td>10146</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>深圳</td>\n",
       "      <td>9098</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>惠州</td>\n",
       "      <td>6557</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>武汉</td>\n",
       "      <td>6534</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>352</th>\n",
       "      <td>南投县</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>353</th>\n",
       "      <td>白沙黎族自治县</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>354</th>\n",
       "      <td>苗栗县</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>355</th>\n",
       "      <td>克孜勒苏柯尔克孜自治州</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>356</th>\n",
       "      <td>台南市</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>357 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            city  login_counts\n",
       "0             广州         27626\n",
       "1             汕头         10146\n",
       "2             深圳          9098\n",
       "3             惠州          6557\n",
       "4             武汉          6534\n",
       "..           ...           ...\n",
       "352          南投县             1\n",
       "353      白沙黎族自治县             1\n",
       "354          苗栗县             1\n",
       "355  克孜勒苏柯尔克孜自治州             1\n",
       "356          台南市             1\n",
       "\n",
       "[357 rows x 2 columns]"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "city_login = pd.DataFrame(columns=[\"city\",\"login_counts\"])\n",
    "city_login['city'] = login.city.value_counts().index\n",
    "city_login['login_counts'] = login.city.value_counts().values\n",
    "city_login"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>city</th>\n",
       "      <th>login_counts</th>\n",
       "      <th>rank</th>\n",
       "      <th>rate</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>广州</td>\n",
       "      <td>27626</td>\n",
       "      <td>1</td>\n",
       "      <td>0.096011</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>汕头</td>\n",
       "      <td>10146</td>\n",
       "      <td>2</td>\n",
       "      <td>0.035261</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>深圳</td>\n",
       "      <td>9098</td>\n",
       "      <td>3</td>\n",
       "      <td>0.031619</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>惠州</td>\n",
       "      <td>6557</td>\n",
       "      <td>4</td>\n",
       "      <td>0.022788</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>武汉</td>\n",
       "      <td>6534</td>\n",
       "      <td>5</td>\n",
       "      <td>0.022708</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>352</th>\n",
       "      <td>南投县</td>\n",
       "      <td>1</td>\n",
       "      <td>353</td>\n",
       "      <td>0.000003</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>353</th>\n",
       "      <td>白沙黎族自治县</td>\n",
       "      <td>1</td>\n",
       "      <td>354</td>\n",
       "      <td>0.000003</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>354</th>\n",
       "      <td>苗栗县</td>\n",
       "      <td>1</td>\n",
       "      <td>355</td>\n",
       "      <td>0.000003</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>355</th>\n",
       "      <td>克孜勒苏柯尔克孜自治州</td>\n",
       "      <td>1</td>\n",
       "      <td>356</td>\n",
       "      <td>0.000003</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>356</th>\n",
       "      <td>台南市</td>\n",
       "      <td>1</td>\n",
       "      <td>357</td>\n",
       "      <td>0.000003</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>357 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            city  login_counts  rank      rate\n",
       "0             广州         27626     1  0.096011\n",
       "1             汕头         10146     2  0.035261\n",
       "2             深圳          9098     3  0.031619\n",
       "3             惠州          6557     4  0.022788\n",
       "4             武汉          6534     5  0.022708\n",
       "..           ...           ...   ...       ...\n",
       "352          南投县             1   353  0.000003\n",
       "353      白沙黎族自治县             1   354  0.000003\n",
       "354          苗栗县             1   355  0.000003\n",
       "355  克孜勒苏柯尔克孜自治州             1   356  0.000003\n",
       "356          台南市             1   357  0.000003\n",
       "\n",
       "[357 rows x 4 columns]"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "city_login['rank'] = city_login['login_counts'].rank(ascending=False,method='first')\n",
    "city_login['rank']= city_login['rank'].values.astype(np.int64)\n",
    "city_login[\"rate\"] = city_login.login_counts/city_login.login_counts.sum()\n",
    "city_login"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>city</th>\n",
       "      <th>login_counts</th>\n",
       "      <th>rank</th>\n",
       "      <th>rate</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>广州</td>\n",
       "      <td>27626</td>\n",
       "      <td>1</td>\n",
       "      <td>0.096011</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>汕头</td>\n",
       "      <td>10146</td>\n",
       "      <td>2</td>\n",
       "      <td>0.035261</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>深圳</td>\n",
       "      <td>9098</td>\n",
       "      <td>3</td>\n",
       "      <td>0.031619</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>惠州</td>\n",
       "      <td>6557</td>\n",
       "      <td>4</td>\n",
       "      <td>0.022788</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>武汉</td>\n",
       "      <td>6534</td>\n",
       "      <td>5</td>\n",
       "      <td>0.022708</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>揭阳</td>\n",
       "      <td>6083</td>\n",
       "      <td>6</td>\n",
       "      <td>0.021141</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>湛江</td>\n",
       "      <td>5500</td>\n",
       "      <td>7</td>\n",
       "      <td>0.019115</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>西安</td>\n",
       "      <td>4941</td>\n",
       "      <td>8</td>\n",
       "      <td>0.017172</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>成都</td>\n",
       "      <td>4647</td>\n",
       "      <td>9</td>\n",
       "      <td>0.016150</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>东莞</td>\n",
       "      <td>4565</td>\n",
       "      <td>10</td>\n",
       "      <td>0.015865</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  city  login_counts  rank      rate\n",
       "0   广州         27626     1  0.096011\n",
       "1   汕头         10146     2  0.035261\n",
       "2   深圳          9098     3  0.031619\n",
       "3   惠州          6557     4  0.022788\n",
       "4   武汉          6534     5  0.022708\n",
       "5   揭阳          6083     6  0.021141\n",
       "6   湛江          5500     7  0.019115\n",
       "7   西安          4941     8  0.017172\n",
       "8   成都          4647     9  0.016150\n",
       "9   东莞          4565    10  0.015865"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "city_top10 = pd.DataFrame()\n",
    "city_top10 = city_login[city_login['rank'].isin(range(1,11))]\n",
    "city_top10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "<ipython-input-28-a357b27d0119>:1: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  city_top10['rate'] = city_top10['rate'].round(4)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>city</th>\n",
       "      <th>login_counts</th>\n",
       "      <th>rank</th>\n",
       "      <th>rate</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>广州</td>\n",
       "      <td>27626</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0960</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>汕头</td>\n",
       "      <td>10146</td>\n",
       "      <td>2</td>\n",
       "      <td>0.0353</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>深圳</td>\n",
       "      <td>9098</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0316</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>惠州</td>\n",
       "      <td>6557</td>\n",
       "      <td>4</td>\n",
       "      <td>0.0228</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>武汉</td>\n",
       "      <td>6534</td>\n",
       "      <td>5</td>\n",
       "      <td>0.0227</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>揭阳</td>\n",
       "      <td>6083</td>\n",
       "      <td>6</td>\n",
       "      <td>0.0211</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>湛江</td>\n",
       "      <td>5500</td>\n",
       "      <td>7</td>\n",
       "      <td>0.0191</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>西安</td>\n",
       "      <td>4941</td>\n",
       "      <td>8</td>\n",
       "      <td>0.0172</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>成都</td>\n",
       "      <td>4647</td>\n",
       "      <td>9</td>\n",
       "      <td>0.0162</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>东莞</td>\n",
       "      <td>4565</td>\n",
       "      <td>10</td>\n",
       "      <td>0.0159</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  city  login_counts  rank    rate\n",
       "0   广州         27626     1  0.0960\n",
       "1   汕头         10146     2  0.0353\n",
       "2   深圳          9098     3  0.0316\n",
       "3   惠州          6557     4  0.0228\n",
       "4   武汉          6534     5  0.0227\n",
       "5   揭阳          6083     6  0.0211\n",
       "6   湛江          5500     7  0.0191\n",
       "7   西安          4941     8  0.0172\n",
       "8   成都          4647     9  0.0162\n",
       "9   东莞          4565    10  0.0159"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "city_top10['rate'] = city_top10['rate'].round(4)\n",
    "city_top10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "try:\n",
    "    city_top10.to_sql('city_top10',engine,index=False)\n",
    "except Exception as e:\n",
    "    print(e)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "city_top10.to_csv('data0/city_top10.csv',encoding='gbk',index=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 6、用户前十学校分布\n",
    "#### 列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>school</th>\n",
       "      <th>users_total</th>\n",
       "      <th>rank</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>长江职业学院</td>\n",
       "      <td>434</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>湖北经济学院</td>\n",
       "      <td>321</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>广东工业大学</td>\n",
       "      <td>237</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>湘潭大学</td>\n",
       "      <td>221</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>韩山师范学院</td>\n",
       "      <td>217</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>981</th>\n",
       "      <td>太原师范学院</td>\n",
       "      <td>1</td>\n",
       "      <td>982</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>982</th>\n",
       "      <td>新疆博尔塔拉蒙古自治州广播电视大学</td>\n",
       "      <td>1</td>\n",
       "      <td>983</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>983</th>\n",
       "      <td>太原大学外语师范学院</td>\n",
       "      <td>1</td>\n",
       "      <td>984</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>984</th>\n",
       "      <td>南京交通职业技术学院</td>\n",
       "      <td>1</td>\n",
       "      <td>985</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>985</th>\n",
       "      <td>日照职业技术学院</td>\n",
       "      <td>1</td>\n",
       "      <td>986</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>986 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                school  users_total  rank\n",
       "0               长江职业学院          434     1\n",
       "1               湖北经济学院          321     2\n",
       "2               广东工业大学          237     3\n",
       "3                 湘潭大学          221     4\n",
       "4               韩山师范学院          217     5\n",
       "..                 ...          ...   ...\n",
       "981             太原师范学院            1   982\n",
       "982  新疆博尔塔拉蒙古自治州广播电视大学            1   983\n",
       "983         太原大学外语师范学院            1   984\n",
       "984         南京交通职业技术学院            1   985\n",
       "985           日照职业技术学院            1   986\n",
       "\n",
       "[986 rows x 3 columns]"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "school = pd.DataFrame(columns=[\"school\",\"users_total\"])\n",
    "school['school'] = user.school.value_counts().index\n",
    "school['users_total'] = user.school.value_counts().values\n",
    "school['rank'] = school['users_total'].rank(ascending=False,method='first')\n",
    "school['rank']= school['rank'].values.astype(np.int64)\n",
    "school"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>school</th>\n",
       "      <th>users_total</th>\n",
       "      <th>rank</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>长江职业学院</td>\n",
       "      <td>434</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>湖北经济学院</td>\n",
       "      <td>321</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>广东工业大学</td>\n",
       "      <td>237</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>湘潭大学</td>\n",
       "      <td>221</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>韩山师范学院</td>\n",
       "      <td>217</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>河北水利电力学院</td>\n",
       "      <td>194</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>黔南民族师范学院</td>\n",
       "      <td>188</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>贵州理工学院</td>\n",
       "      <td>185</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>青岛工学院</td>\n",
       "      <td>183</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>广东技术师范大学天河学院</td>\n",
       "      <td>169</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         school  users_total  rank\n",
       "0        长江职业学院          434     1\n",
       "1        湖北经济学院          321     2\n",
       "2        广东工业大学          237     3\n",
       "3          湘潭大学          221     4\n",
       "4        韩山师范学院          217     5\n",
       "5      河北水利电力学院          194     6\n",
       "6      黔南民族师范学院          188     7\n",
       "7        贵州理工学院          185     8\n",
       "8         青岛工学院          183     9\n",
       "9  广东技术师范大学天河学院          169    10"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "school_top10 = pd.DataFrame()\n",
    "school_top10 = school[school['rank'].isin(range(1,11))]\n",
    "school_top10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "try:\n",
    "    school_top10.to_sql('school_top10',engine,index=False)\n",
    "except Exception as e:\n",
    "    print(e)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "school_top10.to_csv('data0/school_top10.csv',encoding='gbk',index=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 7、工作日和非工作日各时间段登录总频次分布\n",
    "#### 堆叠柱状图，工作日：周一到周五，非工作日：周六、周日"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "user_id                object\n",
       "login_time     datetime64[ns]\n",
       "login_place            object\n",
       "country                object\n",
       "province               object\n",
       "city                   object\n",
       "dtype: object"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time = login.login_time\n",
    "date = pd.Series(time)\n",
    "login['login_time'] = pd.to_datetime(date)\n",
    "login.dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>login_time</th>\n",
       "      <th>login_place</th>\n",
       "      <th>country</th>\n",
       "      <th>province</th>\n",
       "      <th>city</th>\n",
       "      <th>date</th>\n",
       "      <th>time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-06 09:32:47</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-06</td>\n",
       "      <td>09:32:47</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-07 09:28:28</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-07</td>\n",
       "      <td>09:28:28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-07 09:57:44</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-07</td>\n",
       "      <td>09:57:44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-07 10:55:07</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-07</td>\n",
       "      <td>10:55:07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-07 12:28:42</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-07</td>\n",
       "      <td>12:28:42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>387139</th>\n",
       "      <td>用户44247</td>\n",
       "      <td>2020-06-18 07:41:22</td>\n",
       "      <td>中国湖北武汉</td>\n",
       "      <td>中国</td>\n",
       "      <td>湖北</td>\n",
       "      <td>武汉</td>\n",
       "      <td>2020-06-18</td>\n",
       "      <td>07:41:22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>387140</th>\n",
       "      <td>用户44247</td>\n",
       "      <td>2020-06-18 08:13:28</td>\n",
       "      <td>中国湖北</td>\n",
       "      <td>中国</td>\n",
       "      <td>湖北</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-06-18</td>\n",
       "      <td>08:13:28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>387141</th>\n",
       "      <td>用户44248</td>\n",
       "      <td>2020-06-18 09:09:07</td>\n",
       "      <td>中国天津</td>\n",
       "      <td>中国</td>\n",
       "      <td>天津</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-06-18</td>\n",
       "      <td>09:09:07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>387142</th>\n",
       "      <td>用户44249</td>\n",
       "      <td>2020-06-18 09:43:15</td>\n",
       "      <td>中国北京</td>\n",
       "      <td>中国</td>\n",
       "      <td>北京</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-06-18</td>\n",
       "      <td>09:43:15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>387143</th>\n",
       "      <td>用户44250</td>\n",
       "      <td>2020-06-18 09:48:00</td>\n",
       "      <td>中国江西南昌</td>\n",
       "      <td>中国</td>\n",
       "      <td>江西</td>\n",
       "      <td>南昌</td>\n",
       "      <td>2020-06-18</td>\n",
       "      <td>09:48:00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>387144 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        user_id          login_time login_place country province city  \\\n",
       "0           用户3 2018-09-06 09:32:47      中国广东广州      中国       广东   广州   \n",
       "1           用户3 2018-09-07 09:28:28      中国广东广州      中国       广东   广州   \n",
       "2           用户3 2018-09-07 09:57:44      中国广东广州      中国       广东   广州   \n",
       "3           用户3 2018-09-07 10:55:07      中国广东广州      中国       广东   广州   \n",
       "4           用户3 2018-09-07 12:28:42      中国广东广州      中国       广东   广州   \n",
       "...         ...                 ...         ...     ...      ...  ...   \n",
       "387139  用户44247 2020-06-18 07:41:22      中国湖北武汉      中国       湖北   武汉   \n",
       "387140  用户44247 2020-06-18 08:13:28        中国湖北      中国       湖北  NaN   \n",
       "387141  用户44248 2020-06-18 09:09:07        中国天津      中国       天津  NaN   \n",
       "387142  用户44249 2020-06-18 09:43:15        中国北京      中国       北京  NaN   \n",
       "387143  用户44250 2020-06-18 09:48:00      中国江西南昌      中国       江西   南昌   \n",
       "\n",
       "              date      time  \n",
       "0       2018-09-06  09:32:47  \n",
       "1       2018-09-07  09:28:28  \n",
       "2       2018-09-07  09:57:44  \n",
       "3       2018-09-07  10:55:07  \n",
       "4       2018-09-07  12:28:42  \n",
       "...            ...       ...  \n",
       "387139  2020-06-18  07:41:22  \n",
       "387140  2020-06-18  08:13:28  \n",
       "387141  2020-06-18  09:09:07  \n",
       "387142  2020-06-18  09:43:15  \n",
       "387143  2020-06-18  09:48:00  \n",
       "\n",
       "[387144 rows x 8 columns]"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "login['date'] = login['login_time'].dt.date\n",
    "login['time'] = login['login_time'].dt.time\n",
    "login"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### weekday_name:“0”代表星期一，“6”代表星期日"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>login_time</th>\n",
       "      <th>login_place</th>\n",
       "      <th>country</th>\n",
       "      <th>province</th>\n",
       "      <th>city</th>\n",
       "      <th>date</th>\n",
       "      <th>time</th>\n",
       "      <th>weekday_name</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-06 09:32:47</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-06</td>\n",
       "      <td>09:32:47</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-07 09:28:28</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-07</td>\n",
       "      <td>09:28:28</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-07 09:57:44</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-07</td>\n",
       "      <td>09:57:44</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-07 10:55:07</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-07</td>\n",
       "      <td>10:55:07</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-07 12:28:42</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-07</td>\n",
       "      <td>12:28:42</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  user_id          login_time login_place country province city        date  \\\n",
       "0     用户3 2018-09-06 09:32:47      中国广东广州      中国       广东   广州  2018-09-06   \n",
       "1     用户3 2018-09-07 09:28:28      中国广东广州      中国       广东   广州  2018-09-07   \n",
       "2     用户3 2018-09-07 09:57:44      中国广东广州      中国       广东   广州  2018-09-07   \n",
       "3     用户3 2018-09-07 10:55:07      中国广东广州      中国       广东   广州  2018-09-07   \n",
       "4     用户3 2018-09-07 12:28:42      中国广东广州      中国       广东   广州  2018-09-07   \n",
       "\n",
       "       time  weekday_name  \n",
       "0  09:32:47             3  \n",
       "1  09:28:28             4  \n",
       "2  09:57:44             4  \n",
       "3  10:55:07             4  \n",
       "4  12:28:42             4  "
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "login['weekday_name'] = login['login_time'].dt.weekday\n",
    "login.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>login_time</th>\n",
       "      <th>login_place</th>\n",
       "      <th>country</th>\n",
       "      <th>province</th>\n",
       "      <th>city</th>\n",
       "      <th>date</th>\n",
       "      <th>time</th>\n",
       "      <th>weekday_name</th>\n",
       "      <th>day_property</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-06 09:32:47</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-06</td>\n",
       "      <td>09:32:47</td>\n",
       "      <td>3</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-07 09:28:28</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-07</td>\n",
       "      <td>09:28:28</td>\n",
       "      <td>4</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-07 09:57:44</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-07</td>\n",
       "      <td>09:57:44</td>\n",
       "      <td>4</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-07 10:55:07</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-07</td>\n",
       "      <td>10:55:07</td>\n",
       "      <td>4</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-07 12:28:42</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-07</td>\n",
       "      <td>12:28:42</td>\n",
       "      <td>4</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-10 09:18:17</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-10</td>\n",
       "      <td>09:18:17</td>\n",
       "      <td>0</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-10 09:53:39</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-10</td>\n",
       "      <td>09:53:39</td>\n",
       "      <td>0</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-10 11:28:28</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-10</td>\n",
       "      <td>11:28:28</td>\n",
       "      <td>0</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-10 14:04:32</td>\n",
       "      <td>中国北京</td>\n",
       "      <td>中国</td>\n",
       "      <td>北京</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2018-09-10</td>\n",
       "      <td>14:04:32</td>\n",
       "      <td>0</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-10 14:36:23</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-10</td>\n",
       "      <td>14:36:23</td>\n",
       "      <td>0</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  user_id          login_time login_place country province city        date  \\\n",
       "0     用户3 2018-09-06 09:32:47      中国广东广州      中国       广东   广州  2018-09-06   \n",
       "1     用户3 2018-09-07 09:28:28      中国广东广州      中国       广东   广州  2018-09-07   \n",
       "2     用户3 2018-09-07 09:57:44      中国广东广州      中国       广东   广州  2018-09-07   \n",
       "3     用户3 2018-09-07 10:55:07      中国广东广州      中国       广东   广州  2018-09-07   \n",
       "4     用户3 2018-09-07 12:28:42      中国广东广州      中国       广东   广州  2018-09-07   \n",
       "5     用户3 2018-09-10 09:18:17      中国广东广州      中国       广东   广州  2018-09-10   \n",
       "6     用户3 2018-09-10 09:53:39      中国广东广州      中国       广东   广州  2018-09-10   \n",
       "7     用户3 2018-09-10 11:28:28      中国广东广州      中国       广东   广州  2018-09-10   \n",
       "8     用户3 2018-09-10 14:04:32        中国北京      中国       北京  NaN  2018-09-10   \n",
       "9     用户3 2018-09-10 14:36:23      中国广东广州      中国       广东   广州  2018-09-10   \n",
       "\n",
       "       time  weekday_name day_property  \n",
       "0  09:32:47             3          工作日  \n",
       "1  09:28:28             4          工作日  \n",
       "2  09:57:44             4          工作日  \n",
       "3  10:55:07             4          工作日  \n",
       "4  12:28:42             4          工作日  \n",
       "5  09:18:17             0          工作日  \n",
       "6  09:53:39             0          工作日  \n",
       "7  11:28:28             0          工作日  \n",
       "8  14:04:32             0          工作日  \n",
       "9  14:36:23             0          工作日  "
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "login['day_property'] = np.where(login['weekday_name']<5,'工作日','非工作日')\n",
    "login.head(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>login_time</th>\n",
       "      <th>login_place</th>\n",
       "      <th>country</th>\n",
       "      <th>province</th>\n",
       "      <th>city</th>\n",
       "      <th>date</th>\n",
       "      <th>time</th>\n",
       "      <th>weekday_name</th>\n",
       "      <th>day_property</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-06 09:32:47</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-06</td>\n",
       "      <td>09:32:47</td>\n",
       "      <td>3</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-07 09:28:28</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-07</td>\n",
       "      <td>09:28:28</td>\n",
       "      <td>4</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-07 09:57:44</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-07</td>\n",
       "      <td>09:57:44</td>\n",
       "      <td>4</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-07 10:55:07</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-07</td>\n",
       "      <td>10:55:07</td>\n",
       "      <td>4</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-07 12:28:42</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-07</td>\n",
       "      <td>12:28:42</td>\n",
       "      <td>4</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  user_id          login_time login_place country province city        date  \\\n",
       "0     用户3 2018-09-06 09:32:47      中国广东广州      中国       广东   广州  2018-09-06   \n",
       "1     用户3 2018-09-07 09:28:28      中国广东广州      中国       广东   广州  2018-09-07   \n",
       "2     用户3 2018-09-07 09:57:44      中国广东广州      中国       广东   广州  2018-09-07   \n",
       "3     用户3 2018-09-07 10:55:07      中国广东广州      中国       广东   广州  2018-09-07   \n",
       "4     用户3 2018-09-07 12:28:42      中国广东广州      中国       广东   广州  2018-09-07   \n",
       "\n",
       "       time  weekday_name day_property  \n",
       "0  09:32:47             3          工作日  \n",
       "1  09:28:28             4          工作日  \n",
       "2  09:57:44             4          工作日  \n",
       "3  10:55:07             4          工作日  \n",
       "4  12:28:42             4          工作日  "
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "login2 = pd.DataFrame()\n",
    "login2 = login\n",
    "login2.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "user_id                 object\n",
       "login_time      datetime64[ns]\n",
       "login_place             object\n",
       "country                 object\n",
       "province                object\n",
       "city                    object\n",
       "date            datetime64[ns]\n",
       "time                    object\n",
       "weekday_name             int64\n",
       "day_property            object\n",
       "dtype: object"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time = login2.date\n",
    "date = pd.Series(time)\n",
    "login2['date'] = pd.to_datetime(date)\n",
    "login2.dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [],
   "source": [
    "login2['day_property2'] = login2['day_property']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "login2.loc[login2[(login2['date']=='2018/09/29') | (login2['date']=='2018/09/30') | (login2['date']=='2018/12/29')| (login2['date']=='2019/02/02') | (login2['date']=='2019/02/03') | (login2['date']=='2019/04/28')| (login2['date']=='2019/05/05') | (login2['date']=='2019/09/29') | (login2['date']=='2019/10/12')| (login2['date']=='2020/01/19') | (login2['date']=='2020/02/01') | (login2['date']=='2020/04/26') | (login2['date']=='2020/05/09')].index.tolist(),'day_property2'] = '工作日'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>login_time</th>\n",
       "      <th>login_place</th>\n",
       "      <th>country</th>\n",
       "      <th>province</th>\n",
       "      <th>city</th>\n",
       "      <th>date</th>\n",
       "      <th>time</th>\n",
       "      <th>weekday_name</th>\n",
       "      <th>day_property</th>\n",
       "      <th>day_property2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>672</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2019-04-28 13:49:16</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2019-04-28</td>\n",
       "      <td>13:49:16</td>\n",
       "      <td>6</td>\n",
       "      <td>非工作日</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>673</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2019-04-28 16:53:01</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2019-04-28</td>\n",
       "      <td>16:53:01</td>\n",
       "      <td>6</td>\n",
       "      <td>非工作日</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1982</th>\n",
       "      <td>用户5</td>\n",
       "      <td>2019-04-28 18:01:06</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2019-04-28</td>\n",
       "      <td>18:01:06</td>\n",
       "      <td>6</td>\n",
       "      <td>非工作日</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2999</th>\n",
       "      <td>用户17</td>\n",
       "      <td>2019-04-28 14:03:36</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2019-04-28</td>\n",
       "      <td>14:03:36</td>\n",
       "      <td>6</td>\n",
       "      <td>非工作日</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3000</th>\n",
       "      <td>用户17</td>\n",
       "      <td>2019-04-28 16:29:03</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2019-04-28</td>\n",
       "      <td>16:29:03</td>\n",
       "      <td>6</td>\n",
       "      <td>非工作日</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>47993</th>\n",
       "      <td>用户9997</td>\n",
       "      <td>2019-04-28 21:37:44</td>\n",
       "      <td>中国香港</td>\n",
       "      <td>中国</td>\n",
       "      <td>香港</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2019-04-28</td>\n",
       "      <td>21:37:44</td>\n",
       "      <td>6</td>\n",
       "      <td>非工作日</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>47994</th>\n",
       "      <td>用户9998</td>\n",
       "      <td>2019-04-28 21:46:54</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2019-04-28</td>\n",
       "      <td>21:46:54</td>\n",
       "      <td>6</td>\n",
       "      <td>非工作日</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>47995</th>\n",
       "      <td>用户9999</td>\n",
       "      <td>2019-04-28 21:57:19</td>\n",
       "      <td>中国江苏</td>\n",
       "      <td>中国</td>\n",
       "      <td>江苏</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2019-04-28</td>\n",
       "      <td>21:57:19</td>\n",
       "      <td>6</td>\n",
       "      <td>非工作日</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>47996</th>\n",
       "      <td>用户10000</td>\n",
       "      <td>2019-04-28 22:36:31</td>\n",
       "      <td>中国湖南长沙</td>\n",
       "      <td>中国</td>\n",
       "      <td>湖南</td>\n",
       "      <td>长沙</td>\n",
       "      <td>2019-04-28</td>\n",
       "      <td>22:36:31</td>\n",
       "      <td>6</td>\n",
       "      <td>非工作日</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>47997</th>\n",
       "      <td>用户10001</td>\n",
       "      <td>2019-04-28 23:54:08</td>\n",
       "      <td>中国北京</td>\n",
       "      <td>中国</td>\n",
       "      <td>北京</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2019-04-28</td>\n",
       "      <td>23:54:08</td>\n",
       "      <td>6</td>\n",
       "      <td>非工作日</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>142 rows × 11 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       user_id          login_time login_place country province city  \\\n",
       "672        用户3 2019-04-28 13:49:16      中国广东广州      中国       广东   广州   \n",
       "673        用户3 2019-04-28 16:53:01      中国广东广州      中国       广东   广州   \n",
       "1982       用户5 2019-04-28 18:01:06      中国广东广州      中国       广东   广州   \n",
       "2999      用户17 2019-04-28 14:03:36      中国广东广州      中国       广东   广州   \n",
       "3000      用户17 2019-04-28 16:29:03      中国广东广州      中国       广东   广州   \n",
       "...        ...                 ...         ...     ...      ...  ...   \n",
       "47993   用户9997 2019-04-28 21:37:44        中国香港      中国       香港  NaN   \n",
       "47994   用户9998 2019-04-28 21:46:54      中国广东广州      中国       广东   广州   \n",
       "47995   用户9999 2019-04-28 21:57:19        中国江苏      中国       江苏  NaN   \n",
       "47996  用户10000 2019-04-28 22:36:31      中国湖南长沙      中国       湖南   长沙   \n",
       "47997  用户10001 2019-04-28 23:54:08        中国北京      中国       北京  NaN   \n",
       "\n",
       "            date      time  weekday_name day_property day_property2  \n",
       "672   2019-04-28  13:49:16             6         非工作日           工作日  \n",
       "673   2019-04-28  16:53:01             6         非工作日           工作日  \n",
       "1982  2019-04-28  18:01:06             6         非工作日           工作日  \n",
       "2999  2019-04-28  14:03:36             6         非工作日           工作日  \n",
       "3000  2019-04-28  16:29:03             6         非工作日           工作日  \n",
       "...          ...       ...           ...          ...           ...  \n",
       "47993 2019-04-28  21:37:44             6         非工作日           工作日  \n",
       "47994 2019-04-28  21:46:54             6         非工作日           工作日  \n",
       "47995 2019-04-28  21:57:19             6         非工作日           工作日  \n",
       "47996 2019-04-28  22:36:31             6         非工作日           工作日  \n",
       "47997 2019-04-28  23:54:08             6         非工作日           工作日  \n",
       "\n",
       "[142 rows x 11 columns]"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "login2[login2['date']=='2019/04/28']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "hoilday = ['2018/09/24','2018/10/01','2018/10/02','2018/10/03','2018/10/04','2018/10/05','2018/10/06',\n",
    "           '2018/10/07','2018/12/30','2018/12/31','2019/01/01','2019/02/04','2019/02/05','2019/02/06',\n",
    "           '2019/02/07','2019/02/08','2019/02/09','2019/02/10','2019/04/05','2019/05/01','2019/05/02',\n",
    "           '2019/05/03','2019/05/04','2019/06/07','2019/09/13','2019/10/01','2019/10/02','2019/10/03',\n",
    "           '2019/10/04','2019/10/05','2019/10/06','2019/10/07','2020/01/01','2020/01/24','2020/01/25',\n",
    "           '2020/01/26','2020/01/27','2020/01/28','2020/01/29','2020/01/30','2020/04/04','2020/04/05',\n",
    "           '2020/04/06','2020/05/01','2020/05/02','2020/05/03','2020/05/04','2020/05/05']\n",
    "login2.loc[login2[login2['date'].isin(hoilday)].index.tolist(),'day_property2'] = '非工作日'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>login_time</th>\n",
       "      <th>login_place</th>\n",
       "      <th>country</th>\n",
       "      <th>province</th>\n",
       "      <th>city</th>\n",
       "      <th>date</th>\n",
       "      <th>time</th>\n",
       "      <th>weekday_name</th>\n",
       "      <th>day_property</th>\n",
       "      <th>day_property2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>3836</th>\n",
       "      <td>用户24</td>\n",
       "      <td>2019-10-01 13:32:13</td>\n",
       "      <td>中国广东</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2019-10-01</td>\n",
       "      <td>13:32:13</td>\n",
       "      <td>1</td>\n",
       "      <td>工作日</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3837</th>\n",
       "      <td>用户24</td>\n",
       "      <td>2019-10-01 14:07:10</td>\n",
       "      <td>中国广东</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2019-10-01</td>\n",
       "      <td>14:07:10</td>\n",
       "      <td>1</td>\n",
       "      <td>工作日</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3838</th>\n",
       "      <td>用户24</td>\n",
       "      <td>2019-10-01 19:22:39</td>\n",
       "      <td>中国湖南</td>\n",
       "      <td>中国</td>\n",
       "      <td>湖南</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2019-10-01</td>\n",
       "      <td>19:22:39</td>\n",
       "      <td>1</td>\n",
       "      <td>工作日</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5614</th>\n",
       "      <td>用户184</td>\n",
       "      <td>2019-10-01 08:40:59</td>\n",
       "      <td>中国广东潮州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>潮州</td>\n",
       "      <td>2019-10-01</td>\n",
       "      <td>08:40:59</td>\n",
       "      <td>1</td>\n",
       "      <td>工作日</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6276</th>\n",
       "      <td>用户242</td>\n",
       "      <td>2019-10-01 01:14:20</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2019-10-01</td>\n",
       "      <td>01:14:20</td>\n",
       "      <td>1</td>\n",
       "      <td>工作日</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>82606</th>\n",
       "      <td>用户16615</td>\n",
       "      <td>2019-10-01 22:43:33</td>\n",
       "      <td>中国广东惠州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>惠州</td>\n",
       "      <td>2019-10-01</td>\n",
       "      <td>22:43:33</td>\n",
       "      <td>1</td>\n",
       "      <td>工作日</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>82611</th>\n",
       "      <td>用户16616</td>\n",
       "      <td>2019-10-01 22:52:29</td>\n",
       "      <td>中国新疆乌鲁木齐</td>\n",
       "      <td>中国</td>\n",
       "      <td>新疆</td>\n",
       "      <td>乌鲁木齐</td>\n",
       "      <td>2019-10-01</td>\n",
       "      <td>22:52:29</td>\n",
       "      <td>1</td>\n",
       "      <td>工作日</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>82613</th>\n",
       "      <td>用户16617</td>\n",
       "      <td>2019-10-01 23:07:42</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2019-10-01</td>\n",
       "      <td>23:07:42</td>\n",
       "      <td>1</td>\n",
       "      <td>工作日</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>82650</th>\n",
       "      <td>用户16618</td>\n",
       "      <td>2019-10-01 23:41:21</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2019-10-01</td>\n",
       "      <td>23:41:21</td>\n",
       "      <td>1</td>\n",
       "      <td>工作日</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>82651</th>\n",
       "      <td>用户16619</td>\n",
       "      <td>2019-10-01 23:44:05</td>\n",
       "      <td>中国广东佛山</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>佛山</td>\n",
       "      <td>2019-10-01</td>\n",
       "      <td>23:44:05</td>\n",
       "      <td>1</td>\n",
       "      <td>工作日</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>234 rows × 11 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       user_id          login_time login_place country province  city  \\\n",
       "3836      用户24 2019-10-01 13:32:13        中国广东      中国       广东   NaN   \n",
       "3837      用户24 2019-10-01 14:07:10        中国广东      中国       广东   NaN   \n",
       "3838      用户24 2019-10-01 19:22:39        中国湖南      中国       湖南   NaN   \n",
       "5614     用户184 2019-10-01 08:40:59      中国广东潮州      中国       广东    潮州   \n",
       "6276     用户242 2019-10-01 01:14:20      中国广东广州      中国       广东    广州   \n",
       "...        ...                 ...         ...     ...      ...   ...   \n",
       "82606  用户16615 2019-10-01 22:43:33      中国广东惠州      中国       广东    惠州   \n",
       "82611  用户16616 2019-10-01 22:52:29    中国新疆乌鲁木齐      中国       新疆  乌鲁木齐   \n",
       "82613  用户16617 2019-10-01 23:07:42      中国广东广州      中国       广东    广州   \n",
       "82650  用户16618 2019-10-01 23:41:21      中国广东广州      中国       广东    广州   \n",
       "82651  用户16619 2019-10-01 23:44:05      中国广东佛山      中国       广东    佛山   \n",
       "\n",
       "            date      time  weekday_name day_property day_property2  \n",
       "3836  2019-10-01  13:32:13             1          工作日          非工作日  \n",
       "3837  2019-10-01  14:07:10             1          工作日          非工作日  \n",
       "3838  2019-10-01  19:22:39             1          工作日          非工作日  \n",
       "5614  2019-10-01  08:40:59             1          工作日          非工作日  \n",
       "6276  2019-10-01  01:14:20             1          工作日          非工作日  \n",
       "...          ...       ...           ...          ...           ...  \n",
       "82606 2019-10-01  22:43:33             1          工作日          非工作日  \n",
       "82611 2019-10-01  22:52:29             1          工作日          非工作日  \n",
       "82613 2019-10-01  23:07:42             1          工作日          非工作日  \n",
       "82650 2019-10-01  23:41:21             1          工作日          非工作日  \n",
       "82651 2019-10-01  23:44:05             1          工作日          非工作日  \n",
       "\n",
       "[234 rows x 11 columns]"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "login2[login2['date']=='2019/10/01']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [],
   "source": [
    "login2['time'] = pd.to_datetime(login2.time,errors='coerce')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "user_id                  object\n",
       "login_time       datetime64[ns]\n",
       "login_place              object\n",
       "country                  object\n",
       "province                 object\n",
       "city                     object\n",
       "date             datetime64[ns]\n",
       "time             datetime64[ns]\n",
       "weekday_name              int64\n",
       "day_property             object\n",
       "day_property2            object\n",
       "dtype: object"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "login2.dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>time_id</th>\n",
       "      <th>workingday_time</th>\n",
       "      <th>counts</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: [time_id, workingday_time, counts]\n",
       "Index: []"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "work_day = pd.DataFrame(columns=['time_id','workingday_time','counts'])\n",
    "hoilday_day = pd.DataFrame(columns=['time_id','workingday_time','counts'])\n",
    "work_day"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [],
   "source": [
    "time_id = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]\n",
    "workingday_time = ['0:00:01-1:00:00','1:00:01-2:00:00','2:00:01-3:00:00','3:00:01-4:00:00',\n",
    "                   '4:00:01-5:00:00','5:00:01-6:00:00','6:00:01-7:00:00','7:00:01-8:00:00',\n",
    "                   '8:00:01-9:00:00','9:00:01-10:00:00','10:00:01-11:00:00','11:00:01-12:00:00',\n",
    "                   '12:00:01-13:00:00','13:00:01-14:00:00','14:00:01-15:00:00','15:00:01-16:00:00',\n",
    "                   '16:00:01-17:00:00','17:00:01-18:00:00','18:00:01-19:00:00','19:00:01-20:00:00',\n",
    "                   '20:00:01-21:00:00','21:00:01-22:00:00','22:00:01-23:00:00','23:00:01-24:00:00']\n",
    "work_day['time_id'] = time_id\n",
    "hoilday_day['time_id'] = time_id\n",
    "work_day['workingday_time'] = workingday_time\n",
    "hoilday_day['workingday_time'] = workingday_time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>time_id</th>\n",
       "      <th>workingday_time</th>\n",
       "      <th>counts</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>0:00:01-1:00:00</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>1:00:01-2:00:00</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>2:00:01-3:00:00</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>3:00:01-4:00:00</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>4:00:01-5:00:00</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>6</td>\n",
       "      <td>5:00:01-6:00:00</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7</td>\n",
       "      <td>6:00:01-7:00:00</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>8</td>\n",
       "      <td>7:00:01-8:00:00</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>9</td>\n",
       "      <td>8:00:01-9:00:00</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>10</td>\n",
       "      <td>9:00:01-10:00:00</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>11</td>\n",
       "      <td>10:00:01-11:00:00</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>12</td>\n",
       "      <td>11:00:01-12:00:00</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>13</td>\n",
       "      <td>12:00:01-13:00:00</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>14</td>\n",
       "      <td>13:00:01-14:00:00</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>15</td>\n",
       "      <td>14:00:01-15:00:00</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>16</td>\n",
       "      <td>15:00:01-16:00:00</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>17</td>\n",
       "      <td>16:00:01-17:00:00</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>18</td>\n",
       "      <td>17:00:01-18:00:00</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>19</td>\n",
       "      <td>18:00:01-19:00:00</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>20</td>\n",
       "      <td>19:00:01-20:00:00</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>21</td>\n",
       "      <td>20:00:01-21:00:00</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>22</td>\n",
       "      <td>21:00:01-22:00:00</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>23</td>\n",
       "      <td>22:00:01-23:00:00</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>24</td>\n",
       "      <td>23:00:01-24:00:00</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    time_id    workingday_time counts\n",
       "0         1    0:00:01-1:00:00    NaN\n",
       "1         2    1:00:01-2:00:00    NaN\n",
       "2         3    2:00:01-3:00:00    NaN\n",
       "3         4    3:00:01-4:00:00    NaN\n",
       "4         5    4:00:01-5:00:00    NaN\n",
       "5         6    5:00:01-6:00:00    NaN\n",
       "6         7    6:00:01-7:00:00    NaN\n",
       "7         8    7:00:01-8:00:00    NaN\n",
       "8         9    8:00:01-9:00:00    NaN\n",
       "9        10   9:00:01-10:00:00    NaN\n",
       "10       11  10:00:01-11:00:00    NaN\n",
       "11       12  11:00:01-12:00:00    NaN\n",
       "12       13  12:00:01-13:00:00    NaN\n",
       "13       14  13:00:01-14:00:00    NaN\n",
       "14       15  14:00:01-15:00:00    NaN\n",
       "15       16  15:00:01-16:00:00    NaN\n",
       "16       17  16:00:01-17:00:00    NaN\n",
       "17       18  17:00:01-18:00:00    NaN\n",
       "18       19  18:00:01-19:00:00    NaN\n",
       "19       20  19:00:01-20:00:00    NaN\n",
       "20       21  20:00:01-21:00:00    NaN\n",
       "21       22  21:00:01-22:00:00    NaN\n",
       "22       23  22:00:01-23:00:00    NaN\n",
       "23       24  23:00:01-24:00:00    NaN"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "work_day"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>login_time</th>\n",
       "      <th>login_place</th>\n",
       "      <th>country</th>\n",
       "      <th>province</th>\n",
       "      <th>city</th>\n",
       "      <th>date</th>\n",
       "      <th>time</th>\n",
       "      <th>weekday_name</th>\n",
       "      <th>day_property</th>\n",
       "      <th>day_property2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-06 09:32:47</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-06</td>\n",
       "      <td>NaT</td>\n",
       "      <td>3</td>\n",
       "      <td>工作日</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-07 09:28:28</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-07</td>\n",
       "      <td>NaT</td>\n",
       "      <td>4</td>\n",
       "      <td>工作日</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-07 09:57:44</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-07</td>\n",
       "      <td>NaT</td>\n",
       "      <td>4</td>\n",
       "      <td>工作日</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-07 10:55:07</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-07</td>\n",
       "      <td>NaT</td>\n",
       "      <td>4</td>\n",
       "      <td>工作日</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-07 12:28:42</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-07</td>\n",
       "      <td>NaT</td>\n",
       "      <td>4</td>\n",
       "      <td>工作日</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-10 09:18:17</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-10</td>\n",
       "      <td>NaT</td>\n",
       "      <td>0</td>\n",
       "      <td>工作日</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-10 09:53:39</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-10</td>\n",
       "      <td>NaT</td>\n",
       "      <td>0</td>\n",
       "      <td>工作日</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-10 11:28:28</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-10</td>\n",
       "      <td>NaT</td>\n",
       "      <td>0</td>\n",
       "      <td>工作日</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-10 14:04:32</td>\n",
       "      <td>中国北京</td>\n",
       "      <td>中国</td>\n",
       "      <td>北京</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2018-09-10</td>\n",
       "      <td>NaT</td>\n",
       "      <td>0</td>\n",
       "      <td>工作日</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-10 14:36:23</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-10</td>\n",
       "      <td>NaT</td>\n",
       "      <td>0</td>\n",
       "      <td>工作日</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  user_id          login_time login_place country province city       date  \\\n",
       "0     用户3 2018-09-06 09:32:47      中国广东广州      中国       广东   广州 2018-09-06   \n",
       "1     用户3 2018-09-07 09:28:28      中国广东广州      中国       广东   广州 2018-09-07   \n",
       "2     用户3 2018-09-07 09:57:44      中国广东广州      中国       广东   广州 2018-09-07   \n",
       "3     用户3 2018-09-07 10:55:07      中国广东广州      中国       广东   广州 2018-09-07   \n",
       "4     用户3 2018-09-07 12:28:42      中国广东广州      中国       广东   广州 2018-09-07   \n",
       "5     用户3 2018-09-10 09:18:17      中国广东广州      中国       广东   广州 2018-09-10   \n",
       "6     用户3 2018-09-10 09:53:39      中国广东广州      中国       广东   广州 2018-09-10   \n",
       "7     用户3 2018-09-10 11:28:28      中国广东广州      中国       广东   广州 2018-09-10   \n",
       "8     用户3 2018-09-10 14:04:32        中国北京      中国       北京  NaN 2018-09-10   \n",
       "9     用户3 2018-09-10 14:36:23      中国广东广州      中国       广东   广州 2018-09-10   \n",
       "\n",
       "  time  weekday_name day_property day_property2  \n",
       "0  NaT             3          工作日           工作日  \n",
       "1  NaT             4          工作日           工作日  \n",
       "2  NaT             4          工作日           工作日  \n",
       "3  NaT             4          工作日           工作日  \n",
       "4  NaT             4          工作日           工作日  \n",
       "5  NaT             0          工作日           工作日  \n",
       "6  NaT             0          工作日           工作日  \n",
       "7  NaT             0          工作日           工作日  \n",
       "8  NaT             0          工作日           工作日  \n",
       "9  NaT             0          工作日           工作日  "
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "workday = pd.DataFrame()\n",
    "workday = login2[login2.day_property2 == '工作日']\n",
    "workday.head(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "<ipython-input-50-d53b01c85cb8>:1: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  workday['hour'] = workday['login_time'].dt.hour\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>login_time</th>\n",
       "      <th>login_place</th>\n",
       "      <th>country</th>\n",
       "      <th>province</th>\n",
       "      <th>city</th>\n",
       "      <th>date</th>\n",
       "      <th>time</th>\n",
       "      <th>weekday_name</th>\n",
       "      <th>day_property</th>\n",
       "      <th>day_property2</th>\n",
       "      <th>hour</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-06 09:32:47</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-06</td>\n",
       "      <td>NaT</td>\n",
       "      <td>3</td>\n",
       "      <td>工作日</td>\n",
       "      <td>工作日</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-07 09:28:28</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-07</td>\n",
       "      <td>NaT</td>\n",
       "      <td>4</td>\n",
       "      <td>工作日</td>\n",
       "      <td>工作日</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-07 09:57:44</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-07</td>\n",
       "      <td>NaT</td>\n",
       "      <td>4</td>\n",
       "      <td>工作日</td>\n",
       "      <td>工作日</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-07 10:55:07</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-07</td>\n",
       "      <td>NaT</td>\n",
       "      <td>4</td>\n",
       "      <td>工作日</td>\n",
       "      <td>工作日</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-07 12:28:42</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-07</td>\n",
       "      <td>NaT</td>\n",
       "      <td>4</td>\n",
       "      <td>工作日</td>\n",
       "      <td>工作日</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-10 09:18:17</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-10</td>\n",
       "      <td>NaT</td>\n",
       "      <td>0</td>\n",
       "      <td>工作日</td>\n",
       "      <td>工作日</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-10 09:53:39</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-10</td>\n",
       "      <td>NaT</td>\n",
       "      <td>0</td>\n",
       "      <td>工作日</td>\n",
       "      <td>工作日</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-10 11:28:28</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-10</td>\n",
       "      <td>NaT</td>\n",
       "      <td>0</td>\n",
       "      <td>工作日</td>\n",
       "      <td>工作日</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-10 14:04:32</td>\n",
       "      <td>中国北京</td>\n",
       "      <td>中国</td>\n",
       "      <td>北京</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2018-09-10</td>\n",
       "      <td>NaT</td>\n",
       "      <td>0</td>\n",
       "      <td>工作日</td>\n",
       "      <td>工作日</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-10 14:36:23</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-10</td>\n",
       "      <td>NaT</td>\n",
       "      <td>0</td>\n",
       "      <td>工作日</td>\n",
       "      <td>工作日</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  user_id          login_time login_place country province city       date  \\\n",
       "0     用户3 2018-09-06 09:32:47      中国广东广州      中国       广东   广州 2018-09-06   \n",
       "1     用户3 2018-09-07 09:28:28      中国广东广州      中国       广东   广州 2018-09-07   \n",
       "2     用户3 2018-09-07 09:57:44      中国广东广州      中国       广东   广州 2018-09-07   \n",
       "3     用户3 2018-09-07 10:55:07      中国广东广州      中国       广东   广州 2018-09-07   \n",
       "4     用户3 2018-09-07 12:28:42      中国广东广州      中国       广东   广州 2018-09-07   \n",
       "5     用户3 2018-09-10 09:18:17      中国广东广州      中国       广东   广州 2018-09-10   \n",
       "6     用户3 2018-09-10 09:53:39      中国广东广州      中国       广东   广州 2018-09-10   \n",
       "7     用户3 2018-09-10 11:28:28      中国广东广州      中国       广东   广州 2018-09-10   \n",
       "8     用户3 2018-09-10 14:04:32        中国北京      中国       北京  NaN 2018-09-10   \n",
       "9     用户3 2018-09-10 14:36:23      中国广东广州      中国       广东   广州 2018-09-10   \n",
       "\n",
       "  time  weekday_name day_property day_property2  hour  \n",
       "0  NaT             3          工作日           工作日     9  \n",
       "1  NaT             4          工作日           工作日     9  \n",
       "2  NaT             4          工作日           工作日     9  \n",
       "3  NaT             4          工作日           工作日    10  \n",
       "4  NaT             4          工作日           工作日    12  \n",
       "5  NaT             0          工作日           工作日     9  \n",
       "6  NaT             0          工作日           工作日     9  \n",
       "7  NaT             0          工作日           工作日    11  \n",
       "8  NaT             0          工作日           工作日    14  \n",
       "9  NaT             0          工作日           工作日    14  "
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "workday['hour'] = workday['login_time'].dt.hour\n",
    "workday.head(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "user_id                  object\n",
       "login_time       datetime64[ns]\n",
       "login_place              object\n",
       "country                  object\n",
       "province                 object\n",
       "city                     object\n",
       "date             datetime64[ns]\n",
       "time             datetime64[ns]\n",
       "weekday_name              int64\n",
       "day_property             object\n",
       "day_property2            object\n",
       "hour                      int64\n",
       "dtype: object"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "workday.dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [],
   "source": [
    "id1 = workday[workday.hour == 0].hour.count()\n",
    "id2 = workday[workday.hour == 1].hour.count()\n",
    "id3 = workday[workday.hour == 2].hour.count()\n",
    "id4 = workday[workday.hour == 3].hour.count()\n",
    "id5 = workday[workday.hour == 4].hour.count()\n",
    "id6 = workday[workday.hour == 5].hour.count()\n",
    "id7 = workday[workday.hour == 6].hour.count()\n",
    "id8 = workday[workday.hour == 7].hour.count()\n",
    "id9 = workday[workday.hour == 8].hour.count()\n",
    "id10 = workday[workday.hour == 9].hour.count()\n",
    "id11 = workday[workday.hour == 10].hour.count()\n",
    "id12 = workday[workday.hour == 11].hour.count()\n",
    "id13 = workday[workday.hour == 12].hour.count()\n",
    "id14 = workday[workday.hour == 13].hour.count()\n",
    "id15 = workday[workday.hour == 14].hour.count()\n",
    "id16 = workday[workday.hour == 15].hour.count()\n",
    "id17 = workday[workday.hour == 16].hour.count()\n",
    "id18 = workday[workday.hour == 17].hour.count()\n",
    "id19 = workday[workday.hour == 18].hour.count()\n",
    "id20 = workday[workday.hour == 19].hour.count()\n",
    "id21 = workday[workday.hour == 20].hour.count()\n",
    "id22 = workday[workday.hour == 21].hour.count()\n",
    "id23 = workday[workday.hour == 22].hour.count()\n",
    "id24 = workday[workday.hour == 23].hour.count()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>time_id</th>\n",
       "      <th>workingday_time</th>\n",
       "      <th>counts</th>\n",
       "      <th>types</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>0:00:01-1:00:00</td>\n",
       "      <td>3525</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>1:00:01-2:00:00</td>\n",
       "      <td>1317</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>2:00:01-3:00:00</td>\n",
       "      <td>613</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>3:00:01-4:00:00</td>\n",
       "      <td>351</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>4:00:01-5:00:00</td>\n",
       "      <td>216</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>6</td>\n",
       "      <td>5:00:01-6:00:00</td>\n",
       "      <td>242</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7</td>\n",
       "      <td>6:00:01-7:00:00</td>\n",
       "      <td>786</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>8</td>\n",
       "      <td>7:00:01-8:00:00</td>\n",
       "      <td>3734</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>9</td>\n",
       "      <td>8:00:01-9:00:00</td>\n",
       "      <td>13972</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>10</td>\n",
       "      <td>9:00:01-10:00:00</td>\n",
       "      <td>20230</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>11</td>\n",
       "      <td>10:00:01-11:00:00</td>\n",
       "      <td>23061</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>12</td>\n",
       "      <td>11:00:01-12:00:00</td>\n",
       "      <td>17314</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>13</td>\n",
       "      <td>12:00:01-13:00:00</td>\n",
       "      <td>13687</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>14</td>\n",
       "      <td>13:00:01-14:00:00</td>\n",
       "      <td>17128</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>15</td>\n",
       "      <td>14:00:01-15:00:00</td>\n",
       "      <td>21142</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>16</td>\n",
       "      <td>15:00:01-16:00:00</td>\n",
       "      <td>21190</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>17</td>\n",
       "      <td>16:00:01-17:00:00</td>\n",
       "      <td>19958</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>18</td>\n",
       "      <td>17:00:01-18:00:00</td>\n",
       "      <td>15894</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>19</td>\n",
       "      <td>18:00:01-19:00:00</td>\n",
       "      <td>14462</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>20</td>\n",
       "      <td>19:00:01-20:00:00</td>\n",
       "      <td>17685</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>21</td>\n",
       "      <td>20:00:01-21:00:00</td>\n",
       "      <td>17562</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>22</td>\n",
       "      <td>21:00:01-22:00:00</td>\n",
       "      <td>16306</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>23</td>\n",
       "      <td>22:00:01-23:00:00</td>\n",
       "      <td>12667</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>24</td>\n",
       "      <td>23:00:01-24:00:00</td>\n",
       "      <td>7801</td>\n",
       "      <td>工作日</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    time_id    workingday_time  counts types\n",
       "0         1    0:00:01-1:00:00    3525   工作日\n",
       "1         2    1:00:01-2:00:00    1317   工作日\n",
       "2         3    2:00:01-3:00:00     613   工作日\n",
       "3         4    3:00:01-4:00:00     351   工作日\n",
       "4         5    4:00:01-5:00:00     216   工作日\n",
       "5         6    5:00:01-6:00:00     242   工作日\n",
       "6         7    6:00:01-7:00:00     786   工作日\n",
       "7         8    7:00:01-8:00:00    3734   工作日\n",
       "8         9    8:00:01-9:00:00   13972   工作日\n",
       "9        10   9:00:01-10:00:00   20230   工作日\n",
       "10       11  10:00:01-11:00:00   23061   工作日\n",
       "11       12  11:00:01-12:00:00   17314   工作日\n",
       "12       13  12:00:01-13:00:00   13687   工作日\n",
       "13       14  13:00:01-14:00:00   17128   工作日\n",
       "14       15  14:00:01-15:00:00   21142   工作日\n",
       "15       16  15:00:01-16:00:00   21190   工作日\n",
       "16       17  16:00:01-17:00:00   19958   工作日\n",
       "17       18  17:00:01-18:00:00   15894   工作日\n",
       "18       19  18:00:01-19:00:00   14462   工作日\n",
       "19       20  19:00:01-20:00:00   17685   工作日\n",
       "20       21  20:00:01-21:00:00   17562   工作日\n",
       "21       22  21:00:01-22:00:00   16306   工作日\n",
       "22       23  22:00:01-23:00:00   12667   工作日\n",
       "23       24  23:00:01-24:00:00    7801   工作日"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "id = [id1,id2,id3,id4,id5,id6,id7,id8,id9,id10,id11,id12,id13,id14,id15,id16,id17,id18,id19,id20,id21,id22,id23,id24]\n",
    "work_day['counts'] = id\n",
    "work_day['types'] = '工作日'\n",
    "work_day"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [],
   "source": [
    "try:\n",
    "    work_day.to_sql('workday',engine,index=False)\n",
    "except Exception as e:\n",
    "    print(e)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [],
   "source": [
    "work_day.to_csv('data0/workday.csv',encoding='gbk',index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>login_time</th>\n",
       "      <th>login_place</th>\n",
       "      <th>country</th>\n",
       "      <th>province</th>\n",
       "      <th>city</th>\n",
       "      <th>date</th>\n",
       "      <th>time</th>\n",
       "      <th>weekday_name</th>\n",
       "      <th>day_property</th>\n",
       "      <th>day_property2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>38</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-23 00:56:32</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-23</td>\n",
       "      <td>NaT</td>\n",
       "      <td>6</td>\n",
       "      <td>非工作日</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>88</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-10-13 09:19:45</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-10-13</td>\n",
       "      <td>NaT</td>\n",
       "      <td>5</td>\n",
       "      <td>非工作日</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>89</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-10-13 16:02:59</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-10-13</td>\n",
       "      <td>NaT</td>\n",
       "      <td>5</td>\n",
       "      <td>非工作日</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>104</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-10-20 17:10:33</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-10-20</td>\n",
       "      <td>NaT</td>\n",
       "      <td>5</td>\n",
       "      <td>非工作日</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>135</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-11-04 18:02:06</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-11-04</td>\n",
       "      <td>NaT</td>\n",
       "      <td>6</td>\n",
       "      <td>非工作日</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>136</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-11-04 23:04:24</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-11-04</td>\n",
       "      <td>NaT</td>\n",
       "      <td>6</td>\n",
       "      <td>非工作日</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>210</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-12-08 23:44:07</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-12-08</td>\n",
       "      <td>NaT</td>\n",
       "      <td>5</td>\n",
       "      <td>非工作日</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>237</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-12-15 18:59:04</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-12-15</td>\n",
       "      <td>NaT</td>\n",
       "      <td>5</td>\n",
       "      <td>非工作日</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>257</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-12-22 15:15:25</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-12-22</td>\n",
       "      <td>NaT</td>\n",
       "      <td>5</td>\n",
       "      <td>非工作日</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>258</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-12-23 13:17:22</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-12-23</td>\n",
       "      <td>NaT</td>\n",
       "      <td>6</td>\n",
       "      <td>非工作日</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    user_id          login_time login_place country province city       date  \\\n",
       "38      用户3 2018-09-23 00:56:32      中国广东广州      中国       广东   广州 2018-09-23   \n",
       "88      用户3 2018-10-13 09:19:45      中国广东广州      中国       广东   广州 2018-10-13   \n",
       "89      用户3 2018-10-13 16:02:59      中国广东广州      中国       广东   广州 2018-10-13   \n",
       "104     用户3 2018-10-20 17:10:33      中国广东广州      中国       广东   广州 2018-10-20   \n",
       "135     用户3 2018-11-04 18:02:06      中国广东广州      中国       广东   广州 2018-11-04   \n",
       "136     用户3 2018-11-04 23:04:24      中国广东广州      中国       广东   广州 2018-11-04   \n",
       "210     用户3 2018-12-08 23:44:07      中国广东广州      中国       广东   广州 2018-12-08   \n",
       "237     用户3 2018-12-15 18:59:04      中国广东广州      中国       广东   广州 2018-12-15   \n",
       "257     用户3 2018-12-22 15:15:25      中国广东广州      中国       广东   广州 2018-12-22   \n",
       "258     用户3 2018-12-23 13:17:22      中国广东广州      中国       广东   广州 2018-12-23   \n",
       "\n",
       "    time  weekday_name day_property day_property2  \n",
       "38   NaT             6         非工作日          非工作日  \n",
       "88   NaT             5         非工作日          非工作日  \n",
       "89   NaT             5         非工作日          非工作日  \n",
       "104  NaT             5         非工作日          非工作日  \n",
       "135  NaT             6         非工作日          非工作日  \n",
       "136  NaT             6         非工作日          非工作日  \n",
       "210  NaT             5         非工作日          非工作日  \n",
       "237  NaT             5         非工作日          非工作日  \n",
       "257  NaT             5         非工作日          非工作日  \n",
       "258  NaT             6         非工作日          非工作日  "
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hoilday = pd.DataFrame()\n",
    "hoilday = login2[login2.day_property2 == '非工作日']\n",
    "hoilday.head(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "<ipython-input-56-6d268f03567b>:1: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  hoilday['hour'] = hoilday['login_time'].dt.hour\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>login_time</th>\n",
       "      <th>login_place</th>\n",
       "      <th>country</th>\n",
       "      <th>province</th>\n",
       "      <th>city</th>\n",
       "      <th>date</th>\n",
       "      <th>time</th>\n",
       "      <th>weekday_name</th>\n",
       "      <th>day_property</th>\n",
       "      <th>day_property2</th>\n",
       "      <th>hour</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>38</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-23 00:56:32</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-09-23</td>\n",
       "      <td>NaT</td>\n",
       "      <td>6</td>\n",
       "      <td>非工作日</td>\n",
       "      <td>非工作日</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>88</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-10-13 09:19:45</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-10-13</td>\n",
       "      <td>NaT</td>\n",
       "      <td>5</td>\n",
       "      <td>非工作日</td>\n",
       "      <td>非工作日</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>89</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-10-13 16:02:59</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-10-13</td>\n",
       "      <td>NaT</td>\n",
       "      <td>5</td>\n",
       "      <td>非工作日</td>\n",
       "      <td>非工作日</td>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>104</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-10-20 17:10:33</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-10-20</td>\n",
       "      <td>NaT</td>\n",
       "      <td>5</td>\n",
       "      <td>非工作日</td>\n",
       "      <td>非工作日</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>135</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-11-04 18:02:06</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-11-04</td>\n",
       "      <td>NaT</td>\n",
       "      <td>6</td>\n",
       "      <td>非工作日</td>\n",
       "      <td>非工作日</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>136</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-11-04 23:04:24</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-11-04</td>\n",
       "      <td>NaT</td>\n",
       "      <td>6</td>\n",
       "      <td>非工作日</td>\n",
       "      <td>非工作日</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>210</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-12-08 23:44:07</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-12-08</td>\n",
       "      <td>NaT</td>\n",
       "      <td>5</td>\n",
       "      <td>非工作日</td>\n",
       "      <td>非工作日</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>237</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-12-15 18:59:04</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-12-15</td>\n",
       "      <td>NaT</td>\n",
       "      <td>5</td>\n",
       "      <td>非工作日</td>\n",
       "      <td>非工作日</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>257</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-12-22 15:15:25</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-12-22</td>\n",
       "      <td>NaT</td>\n",
       "      <td>5</td>\n",
       "      <td>非工作日</td>\n",
       "      <td>非工作日</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>258</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-12-23 13:17:22</td>\n",
       "      <td>中国广东广州</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>2018-12-23</td>\n",
       "      <td>NaT</td>\n",
       "      <td>6</td>\n",
       "      <td>非工作日</td>\n",
       "      <td>非工作日</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    user_id          login_time login_place country province city       date  \\\n",
       "38      用户3 2018-09-23 00:56:32      中国广东广州      中国       广东   广州 2018-09-23   \n",
       "88      用户3 2018-10-13 09:19:45      中国广东广州      中国       广东   广州 2018-10-13   \n",
       "89      用户3 2018-10-13 16:02:59      中国广东广州      中国       广东   广州 2018-10-13   \n",
       "104     用户3 2018-10-20 17:10:33      中国广东广州      中国       广东   广州 2018-10-20   \n",
       "135     用户3 2018-11-04 18:02:06      中国广东广州      中国       广东   广州 2018-11-04   \n",
       "136     用户3 2018-11-04 23:04:24      中国广东广州      中国       广东   广州 2018-11-04   \n",
       "210     用户3 2018-12-08 23:44:07      中国广东广州      中国       广东   广州 2018-12-08   \n",
       "237     用户3 2018-12-15 18:59:04      中国广东广州      中国       广东   广州 2018-12-15   \n",
       "257     用户3 2018-12-22 15:15:25      中国广东广州      中国       广东   广州 2018-12-22   \n",
       "258     用户3 2018-12-23 13:17:22      中国广东广州      中国       广东   广州 2018-12-23   \n",
       "\n",
       "    time  weekday_name day_property day_property2  hour  \n",
       "38   NaT             6         非工作日          非工作日     0  \n",
       "88   NaT             5         非工作日          非工作日     9  \n",
       "89   NaT             5         非工作日          非工作日    16  \n",
       "104  NaT             5         非工作日          非工作日    17  \n",
       "135  NaT             6         非工作日          非工作日    18  \n",
       "136  NaT             6         非工作日          非工作日    23  \n",
       "210  NaT             5         非工作日          非工作日    23  \n",
       "237  NaT             5         非工作日          非工作日    18  \n",
       "257  NaT             5         非工作日          非工作日    15  \n",
       "258  NaT             6         非工作日          非工作日    13  "
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hoilday['hour'] = hoilday['login_time'].dt.hour\n",
    "hoilday.head(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [],
   "source": [
    "id1 = hoilday[hoilday.hour == 0].hour.count()\n",
    "id2 = hoilday[hoilday.hour == 1].hour.count()\n",
    "id3 = hoilday[hoilday.hour == 2].hour.count()\n",
    "id4 = hoilday[hoilday.hour == 3].hour.count()\n",
    "id5 = hoilday[hoilday.hour == 4].hour.count()\n",
    "id6 = hoilday[hoilday.hour == 5].hour.count()\n",
    "id7 = hoilday[hoilday.hour == 6].hour.count()\n",
    "id8 = hoilday[hoilday.hour == 7].hour.count()\n",
    "id9 = hoilday[hoilday.hour == 8].hour.count()\n",
    "id10 = hoilday[hoilday.hour == 9].hour.count()\n",
    "id11 = hoilday[hoilday.hour == 10].hour.count()\n",
    "id12 = hoilday[hoilday.hour == 11].hour.count()\n",
    "id13 = hoilday[hoilday.hour == 12].hour.count()\n",
    "id14 = hoilday[hoilday.hour == 13].hour.count()\n",
    "id15 = hoilday[hoilday.hour == 14].hour.count()\n",
    "id16 = hoilday[hoilday.hour == 15].hour.count()\n",
    "id17 = hoilday[hoilday.hour == 16].hour.count()\n",
    "id18 = hoilday[hoilday.hour == 17].hour.count()\n",
    "id19 = hoilday[hoilday.hour == 18].hour.count()\n",
    "id20 = hoilday[hoilday.hour == 19].hour.count()\n",
    "id21 = hoilday[hoilday.hour == 20].hour.count()\n",
    "id22 = hoilday[hoilday.hour == 21].hour.count()\n",
    "id23 = hoilday[hoilday.hour == 22].hour.count()\n",
    "id24 = hoilday[hoilday.hour == 23].hour.count()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>time_id</th>\n",
       "      <th>workingday_time</th>\n",
       "      <th>counts</th>\n",
       "      <th>types</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>0:00:01-1:00:00</td>\n",
       "      <td>1533</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>1:00:01-2:00:00</td>\n",
       "      <td>626</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>2:00:01-3:00:00</td>\n",
       "      <td>322</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>3:00:01-4:00:00</td>\n",
       "      <td>147</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>4:00:01-5:00:00</td>\n",
       "      <td>95</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>6</td>\n",
       "      <td>5:00:01-6:00:00</td>\n",
       "      <td>118</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7</td>\n",
       "      <td>6:00:01-7:00:00</td>\n",
       "      <td>297</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>8</td>\n",
       "      <td>7:00:01-8:00:00</td>\n",
       "      <td>1131</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>9</td>\n",
       "      <td>8:00:01-9:00:00</td>\n",
       "      <td>3845</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>10</td>\n",
       "      <td>9:00:01-10:00:00</td>\n",
       "      <td>6395</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>11</td>\n",
       "      <td>10:00:01-11:00:00</td>\n",
       "      <td>7522</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>12</td>\n",
       "      <td>11:00:01-12:00:00</td>\n",
       "      <td>6562</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>13</td>\n",
       "      <td>12:00:01-13:00:00</td>\n",
       "      <td>5481</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>14</td>\n",
       "      <td>13:00:01-14:00:00</td>\n",
       "      <td>6076</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>15</td>\n",
       "      <td>14:00:01-15:00:00</td>\n",
       "      <td>7173</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>16</td>\n",
       "      <td>15:00:01-16:00:00</td>\n",
       "      <td>7638</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>17</td>\n",
       "      <td>16:00:01-17:00:00</td>\n",
       "      <td>7138</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>18</td>\n",
       "      <td>17:00:01-18:00:00</td>\n",
       "      <td>6216</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>19</td>\n",
       "      <td>18:00:01-19:00:00</td>\n",
       "      <td>5454</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>20</td>\n",
       "      <td>19:00:01-20:00:00</td>\n",
       "      <td>7228</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>21</td>\n",
       "      <td>20:00:01-21:00:00</td>\n",
       "      <td>8111</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>22</td>\n",
       "      <td>21:00:01-22:00:00</td>\n",
       "      <td>7420</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>23</td>\n",
       "      <td>22:00:01-23:00:00</td>\n",
       "      <td>6006</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>24</td>\n",
       "      <td>23:00:01-24:00:00</td>\n",
       "      <td>3767</td>\n",
       "      <td>非工作日</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    time_id    workingday_time  counts types\n",
       "0         1    0:00:01-1:00:00    1533  非工作日\n",
       "1         2    1:00:01-2:00:00     626  非工作日\n",
       "2         3    2:00:01-3:00:00     322  非工作日\n",
       "3         4    3:00:01-4:00:00     147  非工作日\n",
       "4         5    4:00:01-5:00:00      95  非工作日\n",
       "5         6    5:00:01-6:00:00     118  非工作日\n",
       "6         7    6:00:01-7:00:00     297  非工作日\n",
       "7         8    7:00:01-8:00:00    1131  非工作日\n",
       "8         9    8:00:01-9:00:00    3845  非工作日\n",
       "9        10   9:00:01-10:00:00    6395  非工作日\n",
       "10       11  10:00:01-11:00:00    7522  非工作日\n",
       "11       12  11:00:01-12:00:00    6562  非工作日\n",
       "12       13  12:00:01-13:00:00    5481  非工作日\n",
       "13       14  13:00:01-14:00:00    6076  非工作日\n",
       "14       15  14:00:01-15:00:00    7173  非工作日\n",
       "15       16  15:00:01-16:00:00    7638  非工作日\n",
       "16       17  16:00:01-17:00:00    7138  非工作日\n",
       "17       18  17:00:01-18:00:00    6216  非工作日\n",
       "18       19  18:00:01-19:00:00    5454  非工作日\n",
       "19       20  19:00:01-20:00:00    7228  非工作日\n",
       "20       21  20:00:01-21:00:00    8111  非工作日\n",
       "21       22  21:00:01-22:00:00    7420  非工作日\n",
       "22       23  22:00:01-23:00:00    6006  非工作日\n",
       "23       24  23:00:01-24:00:00    3767  非工作日"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "id = [id1,id2,id3,id4,id5,id6,id7,id8,id9,id10,id11,id12,id13,id14,id15,id16,id17,id18,id19,id20,id21,id22,id23,id24]\n",
    "hoilday_day['counts'] = id\n",
    "hoilday_day['types'] = '非工作日'\n",
    "hoilday_day"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 133,
   "metadata": {},
   "outputs": [],
   "source": [
    "try:\n",
    "    hoilday_day.to_sql('hoilday',engine,index=False)\n",
    "except Exception as e:\n",
    "    print(e)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [],
   "source": [
    "hoilday_day.to_csv('data0/hoilday.csv',encoding='gbk',index=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 8、流失用户的流失天数\n",
    "#### 面积折线图，流失天数=该平台上所有用户最近访问平台时间与数据观察窗口截止时间的差值，记为数据观察窗口截止时间（如：数据的采集截止时间为2020年6 月18日），T[i]为用户 i 的最近访问时间，Q[i]=T[end] − T[i]，若Q[i]> 90天，则称用户i为流失用户。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>register_time</th>\n",
       "      <th>recently_logged</th>\n",
       "      <th>number_of_classes_join</th>\n",
       "      <th>number_of_classes_out</th>\n",
       "      <th>learn_time</th>\n",
       "      <th>school</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>用户44251</td>\n",
       "      <td>2020-06-18 09:49:00</td>\n",
       "      <td>2020-06-18 09:49:00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>41.25</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>用户44250</td>\n",
       "      <td>2020-06-18 09:47:00</td>\n",
       "      <td>2020-06-18 09:48:00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>用户44249</td>\n",
       "      <td>2020-06-18 09:43:00</td>\n",
       "      <td>2020-06-18 09:43:00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>16.22</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>用户44248</td>\n",
       "      <td>2020-06-18 09:09:00</td>\n",
       "      <td>2020-06-18 09:09:00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>用户44247</td>\n",
       "      <td>2020-06-18 07:41:00</td>\n",
       "      <td>2020-06-18 08:15:00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.80</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   user_id        register_time      recently_logged  number_of_classes_join  \\\n",
       "0  用户44251  2020-06-18 09:49:00  2020-06-18 09:49:00                       0   \n",
       "1  用户44250  2020-06-18 09:47:00  2020-06-18 09:48:00                       0   \n",
       "2  用户44249  2020-06-18 09:43:00  2020-06-18 09:43:00                       0   \n",
       "3  用户44248  2020-06-18 09:09:00  2020-06-18 09:09:00                       0   \n",
       "4  用户44247  2020-06-18 07:41:00  2020-06-18 08:15:00                       0   \n",
       "\n",
       "   number_of_classes_out  learn_time school  \n",
       "0                      0       41.25    NaN  \n",
       "1                      0        0.00    NaN  \n",
       "2                      0       16.22    NaN  \n",
       "3                      0        0.00    NaN  \n",
       "4                      0        1.80    NaN  "
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "user_id                    object\n",
       "register_time              object\n",
       "recently_logged            object\n",
       "number_of_classes_join      int64\n",
       "number_of_classes_out       int64\n",
       "learn_time                float64\n",
       "school                     object\n",
       "dtype: object"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user.dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [],
   "source": [
    "user2 = pd.DataFrame()\n",
    "user2 = user"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "user_id                           object\n",
       "register_time                     object\n",
       "recently_logged           datetime64[ns]\n",
       "number_of_classes_join             int64\n",
       "number_of_classes_out              int64\n",
       "learn_time                       float64\n",
       "school                            object\n",
       "dtype: object"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time = user2.recently_logged\n",
    "date = pd.Series(time)\n",
    "user2['recently_logged'] = pd.to_datetime(date)\n",
    "user2.dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>register_time</th>\n",
       "      <th>recently_logged</th>\n",
       "      <th>number_of_classes_join</th>\n",
       "      <th>number_of_classes_out</th>\n",
       "      <th>learn_time</th>\n",
       "      <th>school</th>\n",
       "      <th>time_difference</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>用户44251</td>\n",
       "      <td>2020-06-18 09:49:00</td>\n",
       "      <td>2020-06-18 09:49:00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>41.25</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>用户44250</td>\n",
       "      <td>2020-06-18 09:47:00</td>\n",
       "      <td>2020-06-18 09:48:00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>用户44249</td>\n",
       "      <td>2020-06-18 09:43:00</td>\n",
       "      <td>2020-06-18 09:43:00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>16.22</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>用户44248</td>\n",
       "      <td>2020-06-18 09:09:00</td>\n",
       "      <td>2020-06-18 09:09:00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>用户44247</td>\n",
       "      <td>2020-06-18 07:41:00</td>\n",
       "      <td>2020-06-18 08:15:00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.80</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43710</th>\n",
       "      <td>用户6</td>\n",
       "      <td>2018-09-11 16:13:00</td>\n",
       "      <td>2018-09-11 16:14:00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>646</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43711</th>\n",
       "      <td>用户5</td>\n",
       "      <td>2018-09-10 15:48:00</td>\n",
       "      <td>2020-06-15 17:13:00</td>\n",
       "      <td>9</td>\n",
       "      <td>5</td>\n",
       "      <td>2116.15</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43712</th>\n",
       "      <td>用户4</td>\n",
       "      <td>2018-09-10 14:15:00</td>\n",
       "      <td>2020-06-05 09:50:00</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>341.20</td>\n",
       "      <td>NaN</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43713</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-04 13:32:00</td>\n",
       "      <td>2020-06-18 09:18:00</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>370.35</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43714</th>\n",
       "      <td>用户1</td>\n",
       "      <td>2018-09-03 10:00:00</td>\n",
       "      <td>2018-11-04 11:20:00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>592</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>43715 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       user_id        register_time     recently_logged  \\\n",
       "0      用户44251  2020-06-18 09:49:00 2020-06-18 09:49:00   \n",
       "1      用户44250  2020-06-18 09:47:00 2020-06-18 09:48:00   \n",
       "2      用户44249  2020-06-18 09:43:00 2020-06-18 09:43:00   \n",
       "3      用户44248  2020-06-18 09:09:00 2020-06-18 09:09:00   \n",
       "4      用户44247  2020-06-18 07:41:00 2020-06-18 08:15:00   \n",
       "...        ...                  ...                 ...   \n",
       "43710      用户6  2018-09-11 16:13:00 2018-09-11 16:14:00   \n",
       "43711      用户5  2018-09-10 15:48:00 2020-06-15 17:13:00   \n",
       "43712      用户4  2018-09-10 14:15:00 2020-06-05 09:50:00   \n",
       "43713      用户3  2018-09-04 13:32:00 2020-06-18 09:18:00   \n",
       "43714      用户1  2018-09-03 10:00:00 2018-11-04 11:20:00   \n",
       "\n",
       "       number_of_classes_join  number_of_classes_out  learn_time school  \\\n",
       "0                           0                      0       41.25    NaN   \n",
       "1                           0                      0        0.00    NaN   \n",
       "2                           0                      0       16.22    NaN   \n",
       "3                           0                      0        0.00    NaN   \n",
       "4                           0                      0        1.80    NaN   \n",
       "...                       ...                    ...         ...    ...   \n",
       "43710                       0                      0        0.00    NaN   \n",
       "43711                       9                      5     2116.15    NaN   \n",
       "43712                       4                      0      341.20    NaN   \n",
       "43713                       2                      1      370.35    NaN   \n",
       "43714                       0                      0        0.00    NaN   \n",
       "\n",
       "       time_difference  \n",
       "0                    0  \n",
       "1                    0  \n",
       "2                    0  \n",
       "3                    0  \n",
       "4                    0  \n",
       "...                ...  \n",
       "43710              646  \n",
       "43711                3  \n",
       "43712               13  \n",
       "43713                0  \n",
       "43714              592  \n",
       "\n",
       "[43715 rows x 8 columns]"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user2['time_difference'] = ((pd.to_datetime('2020-06-19 00:00:00') - user2['recently_logged'])/pd.Timedelta(1,'D')).fillna(0).astype(int)\n",
    "user2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>register_time</th>\n",
       "      <th>recently_logged</th>\n",
       "      <th>number_of_classes_join</th>\n",
       "      <th>number_of_classes_out</th>\n",
       "      <th>learn_time</th>\n",
       "      <th>school</th>\n",
       "      <th>time_difference</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>9468</th>\n",
       "      <td>用户34552</td>\n",
       "      <td>2020-03-19 22:59:00</td>\n",
       "      <td>2020-03-19 23:00:00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>12.33</td>\n",
       "      <td>NaN</td>\n",
       "      <td>91</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9469</th>\n",
       "      <td>用户34551</td>\n",
       "      <td>2020-03-19 22:58:00</td>\n",
       "      <td>2020-03-19 22:59:00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>76.35</td>\n",
       "      <td>NaN</td>\n",
       "      <td>91</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9470</th>\n",
       "      <td>用户34550</td>\n",
       "      <td>2020-03-19 22:27:00</td>\n",
       "      <td>2020-03-19 22:49:00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>91</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9471</th>\n",
       "      <td>用户34549</td>\n",
       "      <td>2020-03-19 22:23:00</td>\n",
       "      <td>2020-03-19 22:23:00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>91</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9472</th>\n",
       "      <td>用户34548</td>\n",
       "      <td>2020-03-19 22:16:00</td>\n",
       "      <td>2020-03-19 22:26:00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>55.80</td>\n",
       "      <td>NaN</td>\n",
       "      <td>91</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43706</th>\n",
       "      <td>用户10</td>\n",
       "      <td>2018-09-18 17:10:00</td>\n",
       "      <td>2018-12-29 15:51:00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>32.88</td>\n",
       "      <td>NaN</td>\n",
       "      <td>537</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43708</th>\n",
       "      <td>用户8</td>\n",
       "      <td>2018-09-18 11:44:00</td>\n",
       "      <td>2019-04-01 16:12:00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>444</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43709</th>\n",
       "      <td>用户7</td>\n",
       "      <td>2018-09-11 16:15:00</td>\n",
       "      <td>2020-03-05 09:50:00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.38</td>\n",
       "      <td>NaN</td>\n",
       "      <td>105</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43710</th>\n",
       "      <td>用户6</td>\n",
       "      <td>2018-09-11 16:13:00</td>\n",
       "      <td>2018-09-11 16:14:00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>646</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43714</th>\n",
       "      <td>用户1</td>\n",
       "      <td>2018-09-03 10:00:00</td>\n",
       "      <td>2018-11-04 11:20:00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>592</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>25339 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       user_id        register_time     recently_logged  \\\n",
       "9468   用户34552  2020-03-19 22:59:00 2020-03-19 23:00:00   \n",
       "9469   用户34551  2020-03-19 22:58:00 2020-03-19 22:59:00   \n",
       "9470   用户34550  2020-03-19 22:27:00 2020-03-19 22:49:00   \n",
       "9471   用户34549  2020-03-19 22:23:00 2020-03-19 22:23:00   \n",
       "9472   用户34548  2020-03-19 22:16:00 2020-03-19 22:26:00   \n",
       "...        ...                  ...                 ...   \n",
       "43706     用户10  2018-09-18 17:10:00 2018-12-29 15:51:00   \n",
       "43708      用户8  2018-09-18 11:44:00 2019-04-01 16:12:00   \n",
       "43709      用户7  2018-09-11 16:15:00 2020-03-05 09:50:00   \n",
       "43710      用户6  2018-09-11 16:13:00 2018-09-11 16:14:00   \n",
       "43714      用户1  2018-09-03 10:00:00 2018-11-04 11:20:00   \n",
       "\n",
       "       number_of_classes_join  number_of_classes_out  learn_time school  \\\n",
       "9468                        0                      0       12.33    NaN   \n",
       "9469                        0                      0       76.35    NaN   \n",
       "9470                        0                      0        0.00    NaN   \n",
       "9471                        0                      0        0.00    NaN   \n",
       "9472                        0                      0       55.80    NaN   \n",
       "...                       ...                    ...         ...    ...   \n",
       "43706                       0                      0       32.88    NaN   \n",
       "43708                       0                      0        0.00    NaN   \n",
       "43709                       0                      0        0.38    NaN   \n",
       "43710                       0                      0        0.00    NaN   \n",
       "43714                       0                      0        0.00    NaN   \n",
       "\n",
       "       time_difference  \n",
       "9468                91  \n",
       "9469                91  \n",
       "9470                91  \n",
       "9471                91  \n",
       "9472                91  \n",
       "...                ...  \n",
       "43706              537  \n",
       "43708              444  \n",
       "43709              105  \n",
       "43710              646  \n",
       "43714              592  \n",
       "\n",
       "[25339 rows x 8 columns]"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lose_user = user2[user2.time_difference > 90]\n",
    "lose_user"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\software\\anaconda3\\lib\\site-packages\\pandas\\core\\frame.py:4308: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  return super().drop(\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>recently_logged</th>\n",
       "      <th>time_difference</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>9468</th>\n",
       "      <td>用户34552</td>\n",
       "      <td>2020-03-19 23:00:00</td>\n",
       "      <td>91</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9469</th>\n",
       "      <td>用户34551</td>\n",
       "      <td>2020-03-19 22:59:00</td>\n",
       "      <td>91</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9470</th>\n",
       "      <td>用户34550</td>\n",
       "      <td>2020-03-19 22:49:00</td>\n",
       "      <td>91</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9471</th>\n",
       "      <td>用户34549</td>\n",
       "      <td>2020-03-19 22:23:00</td>\n",
       "      <td>91</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9472</th>\n",
       "      <td>用户34548</td>\n",
       "      <td>2020-03-19 22:26:00</td>\n",
       "      <td>91</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43706</th>\n",
       "      <td>用户10</td>\n",
       "      <td>2018-12-29 15:51:00</td>\n",
       "      <td>537</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43708</th>\n",
       "      <td>用户8</td>\n",
       "      <td>2019-04-01 16:12:00</td>\n",
       "      <td>444</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43709</th>\n",
       "      <td>用户7</td>\n",
       "      <td>2020-03-05 09:50:00</td>\n",
       "      <td>105</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43710</th>\n",
       "      <td>用户6</td>\n",
       "      <td>2018-09-11 16:14:00</td>\n",
       "      <td>646</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43714</th>\n",
       "      <td>用户1</td>\n",
       "      <td>2018-11-04 11:20:00</td>\n",
       "      <td>592</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>25339 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       user_id     recently_logged  time_difference\n",
       "9468   用户34552 2020-03-19 23:00:00               91\n",
       "9469   用户34551 2020-03-19 22:59:00               91\n",
       "9470   用户34550 2020-03-19 22:49:00               91\n",
       "9471   用户34549 2020-03-19 22:23:00               91\n",
       "9472   用户34548 2020-03-19 22:26:00               91\n",
       "...        ...                 ...              ...\n",
       "43706     用户10 2018-12-29 15:51:00              537\n",
       "43708      用户8 2019-04-01 16:12:00              444\n",
       "43709      用户7 2020-03-05 09:50:00              105\n",
       "43710      用户6 2018-09-11 16:14:00              646\n",
       "43714      用户1 2018-11-04 11:20:00              592\n",
       "\n",
       "[25339 rows x 3 columns]"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lose_user.drop(['register_time','number_of_classes_join','number_of_classes_out','learn_time','school'],axis=1,inplace=True)\n",
    "lose_user"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "115    299\n",
       "123    269\n",
       "452    257\n",
       "109    255\n",
       "451    243\n",
       "      ... \n",
       "574      1\n",
       "611      1\n",
       "606      1\n",
       "628      1\n",
       "605      1\n",
       "Name: time_difference, Length: 525, dtype: int64"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lose_user.time_difference.value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>days</th>\n",
       "      <th>counts</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>115</td>\n",
       "      <td>299</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>123</td>\n",
       "      <td>269</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>452</td>\n",
       "      <td>257</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>109</td>\n",
       "      <td>255</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>451</td>\n",
       "      <td>243</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>520</th>\n",
       "      <td>574</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>521</th>\n",
       "      <td>611</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>522</th>\n",
       "      <td>606</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>523</th>\n",
       "      <td>628</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>524</th>\n",
       "      <td>605</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>525 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     days  counts\n",
       "0     115     299\n",
       "1     123     269\n",
       "2     452     257\n",
       "3     109     255\n",
       "4     451     243\n",
       "..    ...     ...\n",
       "520   574       1\n",
       "521   611       1\n",
       "522   606       1\n",
       "523   628       1\n",
       "524   605       1\n",
       "\n",
       "[525 rows x 2 columns]"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "loseuser_counts = pd.DataFrame(columns=['days','counts'])\n",
    "loseuser_counts['days'] = lose_user.time_difference.value_counts().index\n",
    "loseuser_counts['counts'] = lose_user.time_difference.value_counts().values\n",
    "loseuser_counts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 134,
   "metadata": {},
   "outputs": [],
   "source": [
    "try:\n",
    "    loseuser_counts.to_sql('lose_user',engine,index=False)\n",
    "except Exception as e:\n",
    "    print(e)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [],
   "source": [
    "loseuser_counts.to_csv('data0/lose_user.csv',encoding='gbk',index=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 9、用户课程参与分析\n",
    "#### 玫瑰图，根据用户参与学习的记录，对每门课程的参与人数进行统计，进行人数分阶段统计，100人以下、100-500人、500-1000人、1000-5000人、5000-10000、10000人以上"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>course_id</th>\n",
       "      <th>course_join_time</th>\n",
       "      <th>learn_process</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>用户3</td>\n",
       "      <td>课程106</td>\n",
       "      <td>2020-04-21 10:11:50</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>用户3</td>\n",
       "      <td>课程136</td>\n",
       "      <td>2020-03-05 11:44:36</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>用户3</td>\n",
       "      <td>课程205</td>\n",
       "      <td>2018-09-10 18:17:01</td>\n",
       "      <td>63</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>用户4</td>\n",
       "      <td>课程26</td>\n",
       "      <td>2020-03-31 10:52:51</td>\n",
       "      <td>0</td>\n",
       "      <td>319.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>用户4</td>\n",
       "      <td>课程34</td>\n",
       "      <td>2020-03-31 10:52:49</td>\n",
       "      <td>0</td>\n",
       "      <td>299.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  user_id course_id     course_join_time  learn_process  price\n",
       "0     用户3     课程106  2020-04-21 10:11:50              0    0.0\n",
       "1     用户3     课程136  2020-03-05 11:44:36              1    0.0\n",
       "2     用户3     课程205  2018-09-10 18:17:01             63    0.0\n",
       "3     用户4      课程26  2020-03-31 10:52:51              0  319.0\n",
       "4     用户4      课程34  2020-03-31 10:52:49              0  299.0"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "study_information.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "课程76     13265\n",
       "课程31      9521\n",
       "课程17      8505\n",
       "课程191     7126\n",
       "课程180     6223\n",
       "         ...  \n",
       "课程177        2\n",
       "课程90         1\n",
       "课程93         1\n",
       "课程91         1\n",
       "课程92         1\n",
       "Name: course_id, Length: 241, dtype: int64"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "study_information.course_id.value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>course_id</th>\n",
       "      <th>choice_counts</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>课程76</td>\n",
       "      <td>13265</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>课程31</td>\n",
       "      <td>9521</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>课程17</td>\n",
       "      <td>8505</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>课程191</td>\n",
       "      <td>7126</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>课程180</td>\n",
       "      <td>6223</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  course_id  choice_counts\n",
       "0      课程76          13265\n",
       "1      课程31           9521\n",
       "2      课程17           8505\n",
       "3     课程191           7126\n",
       "4     课程180           6223"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "course_choice = pd.DataFrame(columns=[\"course_id\",\"choice_counts\"])\n",
    "course_choice['course_id'] = study_information.course_id.value_counts().index\n",
    "course_choice['choice_counts'] = study_information.course_id.value_counts().values\n",
    "course_choice.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "course_choice[(course_choice['choice_counts'] > 5000) & (course_choice['choice_counts'] < 10000)].choice_counts.count()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>number_range</th>\n",
       "      <th>counts</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>选课人数10000以上</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>选课人数5000-10000</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>选课人数1000-5000</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>选课人数500-1000</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>选课人数100-500</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>选课人数100以下</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     number_range counts\n",
       "0     选课人数10000以上    NaN\n",
       "1  选课人数5000-10000    NaN\n",
       "2   选课人数1000-5000    NaN\n",
       "3    选课人数500-1000    NaN\n",
       "4     选课人数100-500    NaN\n",
       "5       选课人数100以下    NaN"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "select_course = pd.DataFrame(columns=[\"number_range\",\"counts\"])\n",
    "number_range = ['选课人数10000以上','选课人数5000-10000','选课人数1000-5000','选课人数500-1000','选课人数100-500','选课人数100以下']\n",
    "select_course['number_range'] = number_range\n",
    "select_course"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>number_range</th>\n",
       "      <th>counts</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>选课人数10000以上</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>选课人数5000-10000</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>选课人数1000-5000</td>\n",
       "      <td>32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>选课人数500-1000</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>选课人数100-500</td>\n",
       "      <td>82</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>选课人数100以下</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     number_range  counts\n",
       "0     选课人数10000以上       1\n",
       "1  选课人数5000-10000       8\n",
       "2   选课人数1000-5000      32\n",
       "3    选课人数500-1000      18\n",
       "4     选课人数100-500      82\n",
       "5       选课人数100以下     100"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = course_choice[course_choice['choice_counts'] > 10000].choice_counts.count()\n",
    "b = course_choice[(course_choice['choice_counts'] > 5000) & (course_choice['choice_counts'] <= 10000)].choice_counts.count()\n",
    "c = course_choice[(course_choice['choice_counts'] > 1000) & (course_choice['choice_counts'] <= 5000)].choice_counts.count()\n",
    "d = course_choice[(course_choice['choice_counts'] > 500) & (course_choice['choice_counts'] <= 1000)].choice_counts.count()\n",
    "e = course_choice[(course_choice['choice_counts'] > 100) & (course_choice['choice_counts'] <= 500)].choice_counts.count()\n",
    "f = course_choice[course_choice['choice_counts'] <= 100].choice_counts.count()\n",
    "select_course['counts'] = [a,b,c,d,e,f]\n",
    "select_course"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>number_range</th>\n",
       "      <th>counts</th>\n",
       "      <th>rate</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>选课人数10000以上</td>\n",
       "      <td>1</td>\n",
       "      <td>0.004149</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>选课人数5000-10000</td>\n",
       "      <td>8</td>\n",
       "      <td>0.033195</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>选课人数1000-5000</td>\n",
       "      <td>32</td>\n",
       "      <td>0.132780</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>选课人数500-1000</td>\n",
       "      <td>18</td>\n",
       "      <td>0.074689</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>选课人数100-500</td>\n",
       "      <td>82</td>\n",
       "      <td>0.340249</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>选课人数100以下</td>\n",
       "      <td>100</td>\n",
       "      <td>0.414938</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     number_range  counts      rate\n",
       "0     选课人数10000以上       1  0.004149\n",
       "1  选课人数5000-10000       8  0.033195\n",
       "2   选课人数1000-5000      32  0.132780\n",
       "3    选课人数500-1000      18  0.074689\n",
       "4     选课人数100-500      82  0.340249\n",
       "5       选课人数100以下     100  0.414938"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "select_course[\"rate\"] = select_course.counts/select_course.counts.sum()\n",
    "select_course"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>number_range</th>\n",
       "      <th>counts</th>\n",
       "      <th>rate</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>选课人数10000以上</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0041</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>选课人数5000-10000</td>\n",
       "      <td>8</td>\n",
       "      <td>0.0332</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>选课人数1000-5000</td>\n",
       "      <td>32</td>\n",
       "      <td>0.1328</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>选课人数500-1000</td>\n",
       "      <td>18</td>\n",
       "      <td>0.0747</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>选课人数100-500</td>\n",
       "      <td>82</td>\n",
       "      <td>0.3402</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>选课人数100以下</td>\n",
       "      <td>100</td>\n",
       "      <td>0.4149</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     number_range  counts    rate\n",
       "0     选课人数10000以上       1  0.0041\n",
       "1  选课人数5000-10000       8  0.0332\n",
       "2   选课人数1000-5000      32  0.1328\n",
       "3    选课人数500-1000      18  0.0747\n",
       "4     选课人数100-500      82  0.3402\n",
       "5       选课人数100以下     100  0.4149"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "select_course[\"rate\"] = select_course[\"rate\"].round(4)\n",
    "select_course"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 135,
   "metadata": {},
   "outputs": [],
   "source": [
    "try:\n",
    "    select_course.to_sql('select_course',engine,index=False)\n",
    "except Exception as e:\n",
    "    print(e)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [],
   "source": [
    "select_course.to_csv('data0/select_course.csv',encoding='gbk',index=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 10、受欢迎程度排名前十课程\n",
    "#### 柱状图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>course_id</th>\n",
       "      <th>choice_counts</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>课程76</td>\n",
       "      <td>13265</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>课程31</td>\n",
       "      <td>9521</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>课程17</td>\n",
       "      <td>8505</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>课程191</td>\n",
       "      <td>7126</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>课程180</td>\n",
       "      <td>6223</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>236</th>\n",
       "      <td>课程177</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>237</th>\n",
       "      <td>课程90</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>238</th>\n",
       "      <td>课程93</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>239</th>\n",
       "      <td>课程91</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>240</th>\n",
       "      <td>课程92</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>241 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    course_id  choice_counts\n",
       "0        课程76          13265\n",
       "1        课程31           9521\n",
       "2        课程17           8505\n",
       "3       课程191           7126\n",
       "4       课程180           6223\n",
       "..        ...            ...\n",
       "236     课程177              2\n",
       "237      课程90              1\n",
       "238      课程93              1\n",
       "239      课程91              1\n",
       "240      课程92              1\n",
       "\n",
       "[241 rows x 2 columns]"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "popular_course = pd.DataFrame()\n",
    "popular_course = course_choice\n",
    "popular_course"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>course_id</th>\n",
       "      <th>choice_counts</th>\n",
       "      <th>popularity</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>课程76</td>\n",
       "      <td>13265</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>课程31</td>\n",
       "      <td>9521</td>\n",
       "      <td>0.717732</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>课程17</td>\n",
       "      <td>8505</td>\n",
       "      <td>0.641134</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>课程191</td>\n",
       "      <td>7126</td>\n",
       "      <td>0.537168</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>课程180</td>\n",
       "      <td>6223</td>\n",
       "      <td>0.469089</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>236</th>\n",
       "      <td>课程177</td>\n",
       "      <td>2</td>\n",
       "      <td>0.000075</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>237</th>\n",
       "      <td>课程90</td>\n",
       "      <td>1</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>238</th>\n",
       "      <td>课程93</td>\n",
       "      <td>1</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>239</th>\n",
       "      <td>课程91</td>\n",
       "      <td>1</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>240</th>\n",
       "      <td>课程92</td>\n",
       "      <td>1</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>241 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    course_id  choice_counts  popularity\n",
       "0        课程76          13265    1.000000\n",
       "1        课程31           9521    0.717732\n",
       "2        课程17           8505    0.641134\n",
       "3       课程191           7126    0.537168\n",
       "4       课程180           6223    0.469089\n",
       "..        ...            ...         ...\n",
       "236     课程177              2    0.000075\n",
       "237      课程90              1    0.000000\n",
       "238      课程93              1    0.000000\n",
       "239      课程91              1    0.000000\n",
       "240      课程92              1    0.000000\n",
       "\n",
       "[241 rows x 3 columns]"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "popular_course['popularity'] = (popular_course['choice_counts']-popular_course['choice_counts'].min())/(popular_course['choice_counts'].max()-popular_course['choice_counts'].min())\n",
    "popular_course"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [],
   "source": [
    "popular_course['rank'] = popular_course['popularity'].rank(ascending=False,method='first')\n",
    "popular_course['rank'] = popular_course['rank'].values.astype(np.int64)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>course_id</th>\n",
       "      <th>choice_counts</th>\n",
       "      <th>popularity</th>\n",
       "      <th>rank</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>课程76</td>\n",
       "      <td>13265</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>课程31</td>\n",
       "      <td>9521</td>\n",
       "      <td>0.717732</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>课程17</td>\n",
       "      <td>8505</td>\n",
       "      <td>0.641134</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>课程191</td>\n",
       "      <td>7126</td>\n",
       "      <td>0.537168</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>课程180</td>\n",
       "      <td>6223</td>\n",
       "      <td>0.469089</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>课程52</td>\n",
       "      <td>6105</td>\n",
       "      <td>0.460193</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>课程34</td>\n",
       "      <td>5709</td>\n",
       "      <td>0.430338</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>课程171</td>\n",
       "      <td>5437</td>\n",
       "      <td>0.409831</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>课程50</td>\n",
       "      <td>5342</td>\n",
       "      <td>0.402669</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>课程12</td>\n",
       "      <td>4829</td>\n",
       "      <td>0.363993</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  course_id  choice_counts  popularity  rank\n",
       "0      课程76          13265    1.000000     1\n",
       "1      课程31           9521    0.717732     2\n",
       "2      课程17           8505    0.641134     3\n",
       "3     课程191           7126    0.537168     4\n",
       "4     课程180           6223    0.469089     5\n",
       "5      课程52           6105    0.460193     6\n",
       "6      课程34           5709    0.430338     7\n",
       "7     课程171           5437    0.409831     8\n",
       "8      课程50           5342    0.402669     9\n",
       "9      课程12           4829    0.363993    10"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "popular_top10 = pd.DataFrame()\n",
    "popular_top10 = popular_course[popular_course['rank'].isin(range(1,11))]\n",
    "popular_top10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 136,
   "metadata": {},
   "outputs": [],
   "source": [
    "try:\n",
    "    popular_top10.to_sql('popular_course',engine,index=False)\n",
    "except Exception as e:\n",
    "    print(e)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [],
   "source": [
    "popular_top10.to_csv('data0/popular_course.csv',encoding='gbk',index=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 11、课程价格与平均学习进度关系图\n",
    "#### 箱线图，统计各个课程所对应的用户平均学习时长，绘制课程价格与平均学习进度关系图。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>course_id</th>\n",
       "      <th>choice_counts</th>\n",
       "      <th>popularity</th>\n",
       "      <th>rank</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>课程76</td>\n",
       "      <td>13265</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>课程31</td>\n",
       "      <td>9521</td>\n",
       "      <td>0.717732</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>课程17</td>\n",
       "      <td>8505</td>\n",
       "      <td>0.641134</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>课程191</td>\n",
       "      <td>7126</td>\n",
       "      <td>0.537168</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>课程180</td>\n",
       "      <td>6223</td>\n",
       "      <td>0.469089</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>236</th>\n",
       "      <td>课程177</td>\n",
       "      <td>2</td>\n",
       "      <td>0.000075</td>\n",
       "      <td>237</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>237</th>\n",
       "      <td>课程90</td>\n",
       "      <td>1</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>238</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>238</th>\n",
       "      <td>课程93</td>\n",
       "      <td>1</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>239</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>239</th>\n",
       "      <td>课程91</td>\n",
       "      <td>1</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>240</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>240</th>\n",
       "      <td>课程92</td>\n",
       "      <td>1</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>241</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>241 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    course_id  choice_counts  popularity  rank\n",
       "0        课程76          13265    1.000000     1\n",
       "1        课程31           9521    0.717732     2\n",
       "2        课程17           8505    0.641134     3\n",
       "3       课程191           7126    0.537168     4\n",
       "4       课程180           6223    0.469089     5\n",
       "..        ...            ...         ...   ...\n",
       "236     课程177              2    0.000075   237\n",
       "237      课程90              1    0.000000   238\n",
       "238      课程93              1    0.000000   239\n",
       "239      课程91              1    0.000000   240\n",
       "240      课程92              1    0.000000   241\n",
       "\n",
       "[241 rows x 4 columns]"
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "course_choice"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "course_id\n",
       "课程0       0.000000\n",
       "课程1       0.000000\n",
       "课程10      0.000000\n",
       "课程100     0.000000\n",
       "课程101    53.475104\n",
       "           ...    \n",
       "课程95      5.565217\n",
       "课程96      7.224670\n",
       "课程97      8.156425\n",
       "课程98     14.722997\n",
       "课程99      5.345745\n",
       "Name: learn_process, Length: 241, dtype: float64"
      ]
     },
     "execution_count": 85,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "course_price = study_information['learn_process'].groupby(study_information['course_id']).mean()\n",
    "course_price"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>course_id</th>\n",
       "      <th>avg_process</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>课程0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>课程1</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>课程10</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>课程100</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>课程101</td>\n",
       "      <td>53.475104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>236</th>\n",
       "      <td>课程95</td>\n",
       "      <td>5.565217</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>237</th>\n",
       "      <td>课程96</td>\n",
       "      <td>7.224670</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>238</th>\n",
       "      <td>课程97</td>\n",
       "      <td>8.156425</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>239</th>\n",
       "      <td>课程98</td>\n",
       "      <td>14.722997</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>240</th>\n",
       "      <td>课程99</td>\n",
       "      <td>5.345745</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>241 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    course_id  avg_process\n",
       "0         课程0     0.000000\n",
       "1         课程1     0.000000\n",
       "2        课程10     0.000000\n",
       "3       课程100     0.000000\n",
       "4       课程101    53.475104\n",
       "..        ...          ...\n",
       "236      课程95     5.565217\n",
       "237      课程96     7.224670\n",
       "238      课程97     8.156425\n",
       "239      课程98    14.722997\n",
       "240      课程99     5.345745\n",
       "\n",
       "[241 rows x 2 columns]"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "process_price = pd.DataFrame(columns=['course_id','avg_process'])\n",
    "process_price['course_id'] = course_price.index\n",
    "process_price['avg_process'] = course_price.values\n",
    "process_price"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "course_id\n",
       "课程0      199.0\n",
       "课程1      199.0\n",
       "课程10       0.0\n",
       "课程100    199.0\n",
       "课程101      0.0\n",
       "         ...  \n",
       "课程95     499.0\n",
       "课程96       0.0\n",
       "课程97      29.0\n",
       "课程98      99.0\n",
       "课程99      59.0\n",
       "Name: price, Length: 241, dtype: float64"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "price = study_information['price'].groupby(study_information['course_id']).mean()\n",
    "price"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>course_id</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>课程0</td>\n",
       "      <td>199.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>课程1</td>\n",
       "      <td>199.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>课程10</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>课程100</td>\n",
       "      <td>199.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>课程101</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>236</th>\n",
       "      <td>课程95</td>\n",
       "      <td>499.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>237</th>\n",
       "      <td>课程96</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>238</th>\n",
       "      <td>课程97</td>\n",
       "      <td>29.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>239</th>\n",
       "      <td>课程98</td>\n",
       "      <td>99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>240</th>\n",
       "      <td>课程99</td>\n",
       "      <td>59.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>241 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    course_id  price\n",
       "0         课程0  199.0\n",
       "1         课程1  199.0\n",
       "2        课程10    0.0\n",
       "3       课程100  199.0\n",
       "4       课程101    0.0\n",
       "..        ...    ...\n",
       "236      课程95  499.0\n",
       "237      课程96    0.0\n",
       "238      课程97   29.0\n",
       "239      课程98   99.0\n",
       "240      课程99   59.0\n",
       "\n",
       "[241 rows x 2 columns]"
      ]
     },
     "execution_count": 88,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "price2 = pd.DataFrame(columns=['course_id','price'])\n",
    "price2['course_id'] = price.index\n",
    "price2['price'] = price.values\n",
    "price2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>course_id</th>\n",
       "      <th>avg_process</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>课程0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>199.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>课程1</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>199.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>课程10</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>课程100</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>199.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>课程101</td>\n",
       "      <td>53.475104</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>236</th>\n",
       "      <td>课程95</td>\n",
       "      <td>5.565217</td>\n",
       "      <td>499.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>237</th>\n",
       "      <td>课程96</td>\n",
       "      <td>7.224670</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>238</th>\n",
       "      <td>课程97</td>\n",
       "      <td>8.156425</td>\n",
       "      <td>29.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>239</th>\n",
       "      <td>课程98</td>\n",
       "      <td>14.722997</td>\n",
       "      <td>99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>240</th>\n",
       "      <td>课程99</td>\n",
       "      <td>5.345745</td>\n",
       "      <td>59.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>241 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    course_id  avg_process  price\n",
       "0         课程0     0.000000  199.0\n",
       "1         课程1     0.000000  199.0\n",
       "2        课程10     0.000000    0.0\n",
       "3       课程100     0.000000  199.0\n",
       "4       课程101    53.475104    0.0\n",
       "..        ...          ...    ...\n",
       "236      课程95     5.565217  499.0\n",
       "237      课程96     7.224670    0.0\n",
       "238      课程97     8.156425   29.0\n",
       "239      课程98    14.722997   99.0\n",
       "240      课程99     5.345745   59.0\n",
       "\n",
       "[241 rows x 3 columns]"
      ]
     },
     "execution_count": 89,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "process_price = process_price.merge(price2,how='left',on='course_id')\n",
    "process_price"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>course_id</th>\n",
       "      <th>avg_process</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>课程0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>199.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>课程1</td>\n",
       "      <td>0.00</td>\n",
       "      <td>199.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>课程10</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>课程100</td>\n",
       "      <td>0.00</td>\n",
       "      <td>199.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>课程101</td>\n",
       "      <td>53.48</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>236</th>\n",
       "      <td>课程95</td>\n",
       "      <td>5.57</td>\n",
       "      <td>499.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>237</th>\n",
       "      <td>课程96</td>\n",
       "      <td>7.22</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>238</th>\n",
       "      <td>课程97</td>\n",
       "      <td>8.16</td>\n",
       "      <td>29.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>239</th>\n",
       "      <td>课程98</td>\n",
       "      <td>14.72</td>\n",
       "      <td>99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>240</th>\n",
       "      <td>课程99</td>\n",
       "      <td>5.35</td>\n",
       "      <td>59.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>241 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    course_id  avg_process  price\n",
       "0         课程0         0.00  199.0\n",
       "1         课程1         0.00  199.0\n",
       "2        课程10         0.00    0.0\n",
       "3       课程100         0.00  199.0\n",
       "4       课程101        53.48    0.0\n",
       "..        ...          ...    ...\n",
       "236      课程95         5.57  499.0\n",
       "237      课程96         7.22    0.0\n",
       "238      课程97         8.16   29.0\n",
       "239      课程98        14.72   99.0\n",
       "240      课程99         5.35   59.0\n",
       "\n",
       "[241 rows x 3 columns]"
      ]
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "process_price['avg_process'] = process_price['avg_process'].round(2)\n",
    "process_price"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>course_id</th>\n",
       "      <th>avg_process</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>课程0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>199</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>课程1</td>\n",
       "      <td>0.00</td>\n",
       "      <td>199</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>课程10</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>课程100</td>\n",
       "      <td>0.00</td>\n",
       "      <td>199</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>课程101</td>\n",
       "      <td>53.48</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>236</th>\n",
       "      <td>课程95</td>\n",
       "      <td>5.57</td>\n",
       "      <td>499</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>237</th>\n",
       "      <td>课程96</td>\n",
       "      <td>7.22</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>238</th>\n",
       "      <td>课程97</td>\n",
       "      <td>8.16</td>\n",
       "      <td>29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>239</th>\n",
       "      <td>课程98</td>\n",
       "      <td>14.72</td>\n",
       "      <td>99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>240</th>\n",
       "      <td>课程99</td>\n",
       "      <td>5.35</td>\n",
       "      <td>59</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>241 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    course_id  avg_process  price\n",
       "0         课程0         0.00    199\n",
       "1         课程1         0.00    199\n",
       "2        课程10         0.00      0\n",
       "3       课程100         0.00    199\n",
       "4       课程101        53.48      0\n",
       "..        ...          ...    ...\n",
       "236      课程95         5.57    499\n",
       "237      课程96         7.22      0\n",
       "238      课程97         8.16     29\n",
       "239      课程98        14.72     99\n",
       "240      课程99         5.35     59\n",
       "\n",
       "[241 rows x 3 columns]"
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "process_price['price']= process_price['price'].values.astype(np.int64)\n",
    "process_price"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 137,
   "metadata": {},
   "outputs": [],
   "source": [
    "try:\n",
    "    process_price.to_sql('process_price',engine,index=False)\n",
    "except Exception as e:\n",
    "    print(e)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "process_price.to_csv('data0/process_price.csv',encoding='gbk',index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>course_id</th>\n",
       "      <th>avg_process</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>课程0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>199</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>课程1</td>\n",
       "      <td>0.00</td>\n",
       "      <td>199</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>课程10</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>课程100</td>\n",
       "      <td>0.00</td>\n",
       "      <td>199</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>课程101</td>\n",
       "      <td>53.48</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>236</th>\n",
       "      <td>课程95</td>\n",
       "      <td>5.57</td>\n",
       "      <td>499</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>237</th>\n",
       "      <td>课程96</td>\n",
       "      <td>7.22</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>238</th>\n",
       "      <td>课程97</td>\n",
       "      <td>8.16</td>\n",
       "      <td>29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>239</th>\n",
       "      <td>课程98</td>\n",
       "      <td>14.72</td>\n",
       "      <td>99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>240</th>\n",
       "      <td>课程99</td>\n",
       "      <td>5.35</td>\n",
       "      <td>59</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>241 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    course_id  avg_process  price\n",
       "0         课程0         0.00    199\n",
       "1         课程1         0.00    199\n",
       "2        课程10         0.00      0\n",
       "3       课程100         0.00    199\n",
       "4       课程101        53.48      0\n",
       "..        ...          ...    ...\n",
       "236      课程95         5.57    499\n",
       "237      课程96         7.22      0\n",
       "238      课程97         8.16     29\n",
       "239      课程98        14.72     99\n",
       "240      课程99         5.35     59\n",
       "\n",
       "[241 rows x 3 columns]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "process = pd.read_csv(\"data0/process_price.csv\",encoding='gbk')\n",
    "process"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "p = process['avg_process'].groupby(process['price']).mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>value</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>16.131681</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>29</td>\n",
       "      <td>8.160000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>49</td>\n",
       "      <td>39.730000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>59</td>\n",
       "      <td>5.350000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>79</td>\n",
       "      <td>14.767273</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>99</td>\n",
       "      <td>11.144000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>109</td>\n",
       "      <td>36.694000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>129</td>\n",
       "      <td>8.155714</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>159</td>\n",
       "      <td>15.540000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>169</td>\n",
       "      <td>64.070000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>179</td>\n",
       "      <td>10.320000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>199</td>\n",
       "      <td>24.142174</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>219</td>\n",
       "      <td>8.210000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>229</td>\n",
       "      <td>9.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>299</td>\n",
       "      <td>29.050000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>319</td>\n",
       "      <td>34.196667</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>369</td>\n",
       "      <td>44.050000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>399</td>\n",
       "      <td>8.550000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>499</td>\n",
       "      <td>12.659000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>600</td>\n",
       "      <td>44.940000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>700</td>\n",
       "      <td>69.590000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>800</td>\n",
       "      <td>61.110000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>899</td>\n",
       "      <td>40.048000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>999</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>1299</td>\n",
       "      <td>54.160000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>3000</td>\n",
       "      <td>20.915000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    name      value\n",
       "0      0  16.131681\n",
       "1     29   8.160000\n",
       "2     49  39.730000\n",
       "3     59   5.350000\n",
       "4     79  14.767273\n",
       "5     99  11.144000\n",
       "6    109  36.694000\n",
       "7    129   8.155714\n",
       "8    159  15.540000\n",
       "9    169  64.070000\n",
       "10   179  10.320000\n",
       "11   199  24.142174\n",
       "12   219   8.210000\n",
       "13   229   9.000000\n",
       "14   299  29.050000\n",
       "15   319  34.196667\n",
       "16   369  44.050000\n",
       "17   399   8.550000\n",
       "18   499  12.659000\n",
       "19   600  44.940000\n",
       "20   700  69.590000\n",
       "21   800  61.110000\n",
       "22   899  40.048000\n",
       "23   999   0.000000\n",
       "24  1299  54.160000\n",
       "25  3000  20.915000"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "process2 = pd.DataFrame(columns=['name','value'])\n",
    "process2['name'] = p.index\n",
    "process2['value'] = p.values\n",
    "process2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>value</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>16.13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>29</td>\n",
       "      <td>8.16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>49</td>\n",
       "      <td>39.73</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>59</td>\n",
       "      <td>5.35</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>79</td>\n",
       "      <td>14.77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>99</td>\n",
       "      <td>11.14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>109</td>\n",
       "      <td>36.69</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>129</td>\n",
       "      <td>8.16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>159</td>\n",
       "      <td>15.54</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>169</td>\n",
       "      <td>64.07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>179</td>\n",
       "      <td>10.32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>199</td>\n",
       "      <td>24.14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>219</td>\n",
       "      <td>8.21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>229</td>\n",
       "      <td>9.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>299</td>\n",
       "      <td>29.05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>319</td>\n",
       "      <td>34.20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>369</td>\n",
       "      <td>44.05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>399</td>\n",
       "      <td>8.55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>499</td>\n",
       "      <td>12.66</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>600</td>\n",
       "      <td>44.94</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>700</td>\n",
       "      <td>69.59</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>800</td>\n",
       "      <td>61.11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>899</td>\n",
       "      <td>40.05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>999</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>1299</td>\n",
       "      <td>54.16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>3000</td>\n",
       "      <td>20.92</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    name  value\n",
       "0      0  16.13\n",
       "1     29   8.16\n",
       "2     49  39.73\n",
       "3     59   5.35\n",
       "4     79  14.77\n",
       "5     99  11.14\n",
       "6    109  36.69\n",
       "7    129   8.16\n",
       "8    159  15.54\n",
       "9    169  64.07\n",
       "10   179  10.32\n",
       "11   199  24.14\n",
       "12   219   8.21\n",
       "13   229   9.00\n",
       "14   299  29.05\n",
       "15   319  34.20\n",
       "16   369  44.05\n",
       "17   399   8.55\n",
       "18   499  12.66\n",
       "19   600  44.94\n",
       "20   700  69.59\n",
       "21   800  61.11\n",
       "22   899  40.05\n",
       "23   999   0.00\n",
       "24  1299  54.16\n",
       "25  3000  20.92"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "process2['value'] = process2['value'].round(2)\n",
    "process2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "process2.to_csv('data0/process_price1.csv',encoding='gbk',index=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 12、课程推荐\n",
    "#### 用户输入历史选过的一门课程名称和能接受的课程价格范围，提交返回为其推荐的三门课程名称和对应的价格"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
